Asked  8 Months ago    Answers:  5   Viewed   32 times

If I have two dates 20-4-2010 and 22-4-2010 in two text box and I want the dates to be like this 20, 21, 22. How do I get that ?

 Answers

67

I am pretty sure this has been answered a quadrillion times before, but anyway:

$start = strtotime('20-04-2010 10:00');
$end   = strtotime('22-04-2010 10:00');
for($current = $start; $current <= $end; $current += 86400) {
    echo date('d-m-Y', $current);
}

The 10:00 part is to prevent the code to skip or repeat a day due to daylight saving time.

By giving the number of days:

for($i = 0; $i <= 2; $i++) {
    echo date('d-m-Y', strtotime("20-04-2010 +$i days"));
}

With PHP5.3

$period = new DatePeriod(
    new DateTime('20-04-2010'),
    DateInterval::createFromDateString('+1 day'),
    new DateTime('23-04-2010') // or pass in just the no of days: 2
);

foreach ( $period as $dt ) {
  echo $dt->format( 'd-m-Y' );
}
Wednesday, March 31, 2021
 
axiomer
answered 8 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 8 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 5 Months ago
21

Use the function difftime, with the argument units="hours":

x <- c(ISOdate(2004,1,6), ISOdate(2004,1,1))
difftime(x[1], x[2], units="hours")
Time difference of 120 hours

How did I know where to look?

Well, start by looking at the structure of the object you get when you subtract two times:

str(x[1] - x[2])
Class 'difftime'  atomic [1:1] 5
  ..- attr(*, "units")= chr "days"

So now you know you are dealing with a class of difftime. From here it's easy to find help: See ?difftime

Wednesday, August 25, 2021
 
Andrea Ligios
answered 2 Months ago
20

I think there is no out-of-the-box API to provide the result in the format you mentioned. You need to use the DATEDIFF function to get the difference in the least denomination you need and then divide the result with appropriate value to get the duration in the format required. Something like this:

DECLARE @start DATETIME
DECLARE @end DATETIME
DECLARE @duration INT

SELECT @start = '2009-10-06', @end = '2011-07-15'
SELECT @duration = DATEDIFF(mm, @start, @end)
SELECT CONVERT(NVARCHAR, @duration / 12) + '.' + CONVERT(NVARCHAR, @duration % 12)

This can be better achieved by writing a function that would take the dates and least denomination and returns the duration in the format needed, as it would require TSQL and plain SQL wouldn't suffice.

Wednesday, October 20, 2021
 
Erick Petrucelli
answered 1 Week ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share