homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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

5+ Year Member



 
Msg#: 3784254 posted 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

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3784254 posted 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

WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3784254 posted 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

5+ Year Member



 
Msg#: 3784254 posted 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

WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3784254 posted 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