Click to See Complete Forum and Search --> : Max date
lakshmivijay
12-31-2007, 06:38 AM
Hello
i've small problem in mysql.
in my table i've 2 dates fields createdon,modifiedon.
How can i get which is latest modified record(i.e either record modified date or record created date)
please help me any one its urgent to me
thanks for any help.
vamsi616
12-31-2007, 06:56 AM
Hi,
I think while storing date first time both createdon and modifiedon will be same and if any user logged in 2nd time i suppouse you are updating modifiedon data with currentdate and time. So if you are looking for latest modified record in the table then go with createddon desc and if you are looking when user last loggedin then go with modifiedon date
Thanks,
lakshmivijay
12-31-2007, 07:15 AM
But i need to check both dates
vamsi616
12-31-2007, 07:27 AM
Yeah,
check both dates in the sense , are you looking which date is maximum one ?
lakshmivijay
12-31-2007, 07:31 AM
yes which date is latest one
vamsi616
12-31-2007, 07:33 AM
Yeah,
correct me if i am wrong
I think while storing date first time both createdon and modifiedon will be same and if any user logged in 2nd time i suppouse you are updating modifiedon data with currentdate and time.
If that is the case always modified date is latest date
bubbisthedog
12-31-2007, 08:41 AM
Or you could change your table structure such only one date field exists and another field represents what the date type is ('created', 'modified', etc.). Then all you'd have to do is query the date field...
chazzy
12-31-2007, 08:49 AM
couldn't you use a case statement?
SELECT
case
when mod_date > create_date then mod_date else create_date end as the_date
from your_table
But the design seems iffy at best to me...
lakshmivijay
01-03-2008, 03:29 AM
its working
Thanks for ur reply Dear Chazzy.