sandy1028 Posted January 15, 2008 Share Posted January 15, 2008 Hi, How to decrement the time from current hour of timestamp to last 24hours. I have to manually get the time of the timestamp for last 24 hours by decrementing from the current hour I have tried from 0th hour to 24 hours so please help me in reverse Please help me. $timeincr=10; $time_interval = array(); for($i=0;$i<24;$i++){ if($i<10){ $hour = "0".$i; } else{ $hour = $i; } for($j=0;$j<60;$j=$j+$timeincr){ if($j==0){ $item = $hour.":00"; array_push($time_interval,$item); } else{ $item = $hour.":".$j; array_push($time_interval,$item); } } } Quote Link to comment https://forums.phpfreaks.com/topic/86095-time-value/ Share on other sites More sharing options...
tibberous Posted January 15, 2008 Share Posted January 15, 2008 What? Is English your main language. Quote Link to comment https://forums.phpfreaks.com/topic/86095-time-value/#findComment-439615 Share on other sites More sharing options...
priti Posted January 15, 2008 Share Posted January 15, 2008 Hi, How to decrement the time from current hour of timestamp to last 24hours. I have to manually get the time of the timestamp for last 24 hours by decrementing from the current hour I have tried from 0th hour to 24 hours so please help me in reverse Please help me. $timeincr=10; $time_interval = array(); for($i=0;$i<24;$i++){ if($i<10){ $hour = "0".$i; } else{ $hour = $i; } for($j=0;$j<60;$j=$j+$timeincr){ if($j==0){ $item = $hour.":00"; array_push($time_interval,$item); } else{ $item = $hour.":".$j; array_push($time_interval,$item); } } } It would be gr8 if you can explain 'How to decrement the time from current hour of timestamp to last 24hours.'? what you are trying to achieve why so much of scripting is required for dates?if you want time in 24 hour format you can use PHP in built function date H,i,s . and to get the difference betweeon 2 dates convert the dates in timestamp and get the difference and then convert the format of that timestamp in date format you required. Hope it helps a little bit Regards Quote Link to comment https://forums.phpfreaks.com/topic/86095-time-value/#findComment-439638 Share on other sites More sharing options...
sandy1028 Posted January 15, 2008 Author Share Posted January 15, 2008 Hi, I just want the timestamp value for each ten minutes for last 24hours. Quote Link to comment https://forums.phpfreaks.com/topic/86095-time-value/#findComment-439649 Share on other sites More sharing options...
sandy1028 Posted January 15, 2008 Author Share Posted January 15, 2008 Suppose the timestamp is 2008-01-15 12:00:01 I want the timestamp 2008-01-15 11:50:01 and so on.... decrementing for ten minutes. Quote Link to comment https://forums.phpfreaks.com/topic/86095-time-value/#findComment-439652 Share on other sites More sharing options...
priti Posted January 15, 2008 Share Posted January 15, 2008 Suppose the timestamp is 2008-01-15 12:00:01 I want the timestamp 2008-01-15 11:50:01 and so on.... decrementing for ten minutes. try $t= time(); echo date("m-d-Y H:i:s",$t); $timetostop=mktime(0,0,0,date("m"),date("d")-1,date("y")); $timetostop=date("m-d-Y",$timetostop); $date=date("m-d-Y",$t); while($date != $timetostop) { echo '<br>'.date("m-d-Y H:i:s",$t); $t=$t-10; $date=date("m-d-Y",$t); } Quote Link to comment https://forums.phpfreaks.com/topic/86095-time-value/#findComment-439661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.