I need to assign a specific number like 1559 to today's date and calculate the previous and next days according to this. For example 2 days ago is 1557, yesterday is 1558, today is 1559 tomorrow is 1560, etc. With that, i will create a pagination for the days with post method. My date is in YYYY-MM-DD format and stored in a date variable in mySQL. What should I do to assing numbers to dates and calculate the dates accordingly?
my code looks like this btw:
include ('connect.php');
date_default_timezone_set("Etc/GMT+7");
$timestamp= date("Y-m-d");
$day1=1357;
echo ('<form action="total_inf.php" method="post" name="inf_day">');
for($i=0;$i<10;$i++)
{
$newdate=strtotime('-$i days',strtotime($timestamp));
$newdate = date ( 'Y-m-d' , $newdate );
$prevdays=$day1-$i;
print ('<input type="submit" name="bugun" value="'.$prevdays.'"> ');
}
echo ('</form>');
$day_selected=$_PO开发者_开发知识库ST[bugun];
$sql1="SELECT * FROM userdata WHERE zaman='$timestamp'";
$result1=mysql_query($sql1,$conn);
$current_date = new DateTime('2011-08-10');
$current_date->modify('+1 day'); //next day
$current_date->modify('-1 day');// prev day
$other_date = new DateTime('1970-01-01'); //another date
See DateTime reference
UPDATE:
$day1 = new DateTime();
$day1->modify('-1357 days');
//if you need it to be some fixed date, use $day1= new DateTime("2011-08-01");
$now_date = new DateTime();
for($i=0;$i<10;$i++){
$date_diff = $now_date->diff($zero_date);
$prevdays = $date_diff->format("#a")-$i;
print ('<input type="submit" name="bugun" value="'.$prevdays.'"> ');
}
Works with PHP >= 5.3.0. See DateInterval::format
精彩评论