getting date difference

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

getting date difference

Post by itsmani1 »

hello people...

i m using php/mysql and i need help in qry:
in my DB the table has a date field with data type date and time
now i want to select those rows that are exectly one month old

any help plz.

Code: Select all

$qry "select date from table where date < one_month ";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

oki thanks yaar hope it will work
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Code: Select all

SELECT field FROM table WHERE CURDATE()<=date_end AND CURDATE()>=date_start
Good idea to read the manual, too.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

SELECT * FROM tree
WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) > 8/18/2004

can you tell me :
DATE_SUB(CURDATE(), => what is this
INTERVAL 30 DAY) => what is this

Regards
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Subtract from CURDATE() (current date and time) ... 30 days.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Just check which functions you are using. Most of the current functions are available in MySQL 4.1 and not 4.0. Some servers have still not upgraded.
http://dev.mysql.com/doc/mysql/en/date- ... tions.html
Post Reply