SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old February 25th, 2004, 10:19 AM
Jake_Gibilaro Jake_Gibilaro is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 5 Jake_Gibilaro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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,

Reply With Quote
  #2  
Old February 25th, 2004, 12:55 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
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

Reply With Quote
  #3  
Old February 26th, 2004, 11:43 AM
Jake_Gibilaro Jake_Gibilaro is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 5 Jake_Gibilaro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yeah it won't be a problem to convert

my table. It looks messy but I'll give it a go

Cheers.

Reply With Quote
  #4  
Old February 26th, 2004, 03:24 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Comparing Dates (PHP)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway