speedy33417 Posted January 10, 2007 Share Posted January 10, 2007 I'm working with dates in a db that store in a YYYY-MM-DD HH:MM:SS format. What is the easiest way to do the following? 1) Determining what day of the week that is (Mon, Tue...) 2) Adding one day to it (where it calculates a new month, year, leap year...) 3) Adding one hour to it 4) Calculating the difference between dates Thanks Link to comment https://forums.phpfreaks.com/topic/33579-date-question/ Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 what you do for getting the (Mon, Tue...), is:[code]$date = strtotime($date)$date = date('D', $date);[/code]The rest of them, i am not sure what you mean....Ted Link to comment https://forums.phpfreaks.com/topic/33579-date-question/#findComment-157274 Share on other sites More sharing options...
kenrbnsn Posted January 10, 2007 Share Posted January 10, 2007 In php, take a look at the [url=http://www.php.net/strtotime]strtotime()[/url] and [url=http://www.php.net/date]date()[/url] functions.[code]<?php$str = '2008-02-28 23:30:30';echo date('D',strtotime($str)) . '<br>'; // day of weekecho date ('Y-m-d',strtotime($str . ' + 1 day')). '<br>' // add 1 dayecho date ('Y-m-d g:i A',strtotime($str . ' + 1 hour')) . '<br>' // add 1 hour?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/33579-date-question/#findComment-157286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.