Page 1 of 1
date
Posted: Mon Mar 10, 2003 3:11 pm
by nmotion
I'm new to PHP so this may be a stupid question but here goes.
I want to take the current date and subtract 14 days from that.
The formatting has to be:
ex. 2003-02-24
Posted: Mon Mar 10, 2003 3:27 pm
by daven
check into the PHP date() function
I looked at it...
Posted: Mon Mar 10, 2003 3:29 pm
by nmotion
But found it rather complex compared to ASP.
In ASP I could just say date-14
So any inputs would be appreciated.
Posted: Tue Mar 11, 2003 2:05 am
by twigletmac
Are you trying to do this to put it into a database? Or have you taken it from a database. (Reason I ask is 'cause databases can generally do this stuff themselves and it saves you a few lines of PHP code.)
Mac
Posted: Tue Mar 11, 2003 8:31 am
by nmotion
I need to use it in a sql query.
WHERE $some_date > $current_date-14
Also, I have been trying to figure out how to display the following date:
12-20-2002
As
2002-12-20
with PHP. Yes, I have read about date on php.net but I still can't figure it out. Please help or if you have links to other pages discussing this it would be great.
Posted: Tue Mar 11, 2003 8:41 am
by twigletmac
MySQL can do the date subtraction stuff, you don't need to fiddle about with PHP for that -
Code: Select all
SELECT field1, field2, field3 FROM table WHERE $some_date > DATE_SUB(NOW(), INTERVAL 14 DAY)
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
As for converting 12-20-2002 to 2002-12-20, try something like:
Code: Select all
$date = '12-20-2002';
$dateinfo = explode('-', $date);
$mysql_date = $dateinfo[2].'-'.$dateinfo[0].'-'.$dateinfo[1];
http://www.php.net/manual/en/function.explode.php
Mac
Posted: Tue Mar 11, 2003 9:05 am
by nmotion
Thanks a lot for the help and links.
I got it to work
