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 ?



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
answered 8 Months ago

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:

Related usability ticket:

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

Wednesday, March 31, 2021
answered 8 Months ago

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
answered 5 Months ago

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

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 @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 :