Page 1 of 1
Getting dates
Posted: Fri Dec 09, 2005 4:04 am
by mhouldridge
Hi,
To get the date in php I use....
I would like to retreive a date value 30days in the past. How could I do this?
Posted: Fri Dec 09, 2005 4:11 am
by shiznatix
strtotime() will be able to help you out. many other people will post the code themselves after me but i think its a good idea to learn how that function works and how you can use it with date() to get different dates as this is somthing that people have to deal with very very often.
Posted: Fri Dec 09, 2005 4:18 am
by anjanesh
Code: Select all
echo date("Y-m-d H:i:s", strtotime("-1 day"));
Posted: Fri Dec 09, 2005 4:32 am
by mhouldridge
Thanks for this.
Kinda got it working now, and know where to go from here.
Just wondering also. I looked on the Internet about timestamps. Here is some code I saw;
Code: Select all
// timestamp for 13:56:04 on 18 Jun 2003
echo mktime(13,56,04,06,18,2003)."<br>";
echo date("M d Y, H:i:s",mktime(13,56,04,06,18,2003))."<br>";
// timestamp for 13:56:04 on 18 Jun 2003 + 18 days
echo mktime(13,56,04,06,36,2003)."<br>";
echo date("M d Y, H:i:s",mktime(13,56,04,06,36,2003))."<br>";
Why do people use timestamps method instead of....
Code: Select all
echo date("Y-m-d H:i:s", strtotime("-1 month"));
which seems far cleaner?
I dont quite grasp the difference between timestamp use and strtotime?
Posted: Fri Dec 09, 2005 5:24 am
by anjanesh
I guess
strtotime cannot parse complex
date input formats.