Jump to content

date question


speedy33417

Recommended Posts

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

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 week
echo date ('Y-m-d',strtotime($str . ' + 1 day')). '<br>' // add 1 day
echo 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

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.