Jump to content

[SOLVED] time and date comparisons


gerkintrigg

Recommended Posts

I've been pulling my hair out for the last few days trying to get this to work, but I've finally given up and hope that you guys and girls can help me.

 

$limiter=date(Y)+1;
$limiter=date('m/d').$limiter;
$x_days='7';
while (strtotime($start_date)<=strtotime($limiter)){

echo date('d/m/Y',$start_date).'<BR>';
echo date('d/m/Y',strtotime($limiter)).'<BR><br>';
//echo date('l F d Y',$start_date).' To ';
//echo date('l F d Y', strtotime('+'.$x_days.' days',$start_date)).'<BR>';
$start_date=strtotime('+'.$x_days.' days', $start_date);
}

 

It keeps looping through until it gets to 1970!(?) Any suggestions?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/43668-solved-time-and-date-comparisons/
Share on other sites

You should be doing all your work with the UNIX timestamp, you're using both the UNIX timestamp and the ASCII date string which is where the "1970" value is coming from. Try this:

<?php
$start_date = time();
$limiter=date(Y)+1;
$limiter=strtotime(date('m/d/').$limiter);
$x_days='7';
while ($start_date<=$limiter){

echo date('d/m/Y',$start_date).'<BR>';
echo date('d/m/Y',$limiter).'<BR><br>';
//echo date('l F d Y',$start_date).' To ';
//echo date('l F d Y', strtotime('+'.$x_days.' days',$start_date)).'<BR>';
$start_date=strtotime('+'.$x_days.' days', $start_date);
}
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.