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
date
Moderator: General Moderators
I looked at it...
But found it rather complex compared to ASP.
In ASP I could just say date-14
So any inputs would be appreciated.
In ASP I could just say date-14
So any inputs would be appreciated.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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.
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.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
MySQL can do the date subtraction stuff, you don't need to fiddle about with PHP for that -
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
As for converting 12-20-2002 to 2002-12-20, try something like:
http://www.php.net/manual/en/function.explode.php
Mac
Code: Select all
SELECT field1, field2, field3 FROM table WHERE $some_date > DATE_SUB(NOW(), INTERVAL 14 DAY)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];Mac