homepage Welcome to WebmasterWorld Guest from 184.72.82.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Searching thru dates
dates, mysql
brancook




msg:3784256
 5:40 pm on Nov 11, 2008 (gmt 0)

I have a date column in a table that displays the date for a given record like this "November 10, 2008". What would my sql statement look like if I just wanted to find all of the records from "November".

WHERE Date = "November" doesn't work for me, I get no records found. I need to look past the day and year.

 

jatar_k




msg:3784270
 6:06 pm on Nov 11, 2008 (gmt 0)

you would need to use LIKE

WHERE Date LIKE "November%"

the % represents 'any number of characters'

LifeinAsia




msg:3784280
 6:28 pm on Nov 11, 2008 (gmt 0)

It would be better if you can change the field type (and underlying data) to DATETIME instead of VARCHAR (or at least add another field of type DATETIME). Using VARCHAR fields to store dates is just asking for problems later on.

brancook




msg:3786283
 12:55 pm on Nov 14, 2008 (gmt 0)

Thanks jatar_k

I did set it up as a VARCHAR field, this is actually one of the first databases I've put together. What would it take to change the field type (and underlying data) to DATETIME?

LifeinAsia




msg:3786361
 4:11 pm on Nov 14, 2008 (gmt 0)

Most likely- add another field of DATETIME format, then do a conversion of the "Date" field, then drop the "Date" field after all the values have been converted.

One other suggestion I forgot to mention before, using reserved words (like "Date" or "Time") for field or table names is not a good idea. It often causes major headaches down the road.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved