|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Comparing Dates (PHP)
Hi, I'm currently storing dates in MySQL table as strings
in the form DD/MM/YYYY. I need a way of returning all rows where this date is two months older than the current date. I'm pretty stuck here and would greatly appreciate any help. Cheers, |
|
#2
|
||||
|
||||
|
are they stored as varchar, or as date?
Date stores the information (by default) as YYYYMMDD... you can format the return display in your SELECT statement... and you can do fancy searching If it isn't too late to convert your table over, I highly recommend you do! =) Example: Code:
SELECT *
FROM SomeTable
WHERE UNIX_TIMESTAMP(DATE_FORMAT(date_field,"%Y-%m-%d 00:00:00"))
BETWEEN (UNIX_TIMESTAMP(DATE_FORMAT(CURDATE(),"%Y-%m-%d 00:00:00")))
AND (UNIX_TIMESTAMP(DATE_FORMAT((CURDATE()-interval 2 month),"%Y-%m-%d 00:00:00")));
untested, off the top of my head |
|
#3
|
|||
|
|||
|
Yeah it won't be a problem to convert
my table. It looks messy but I'll give it a go ![]() Cheers. |
|
#4
|
||||
|
||||
|
It does look messy... =)
I tried to format it a bit to make it a little easier... you're better off having a Date field as they're easier to work with... In my example above i'm simply converting it to a UNIX timestamp which is easier to compare with... i'm sure there's ways to make dates compare directly, but this is how i've done it in the past. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Comparing Dates (PHP) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|