Jump to content

help with mysql query varchar to date


syntax101

Recommended Posts

i have a table and my cc_date(varchar type) and the date format is 1/31/2008, 2/28/2008

im having trouble selecting them by range.

 

my query is

 

select * from cc where cc_date >= ?

 

can anybody help me how to query that varchar type to date(format) pls help im using mysql 5.0

Link to comment
https://forums.phpfreaks.com/topic/133349-help-with-mysql-query-varchar-to-date/
Share on other sites

First of all, don't store dates as varchar. This is just one of the problems you will experience if you do.

The DATE, TIME, DATETIME, TIMESTAMP field types were introduced for a reason.

 

Second: not all is lost. You can use STR_TO_DATE() mysql function.

 

 

here is my query

 

SELECT cc_num, cc_jobnumber, emp_name, cc_entry, cc_cc

FROM cc

WHERE STR_TO_DATE('cc_date', '%m/%d/%Y') >= ? (1/1/2008)

 

cc_date contains

 

1/1/2007

1/1/2008

1/2/2007

8/7/2008

1/31/2007

 

result must be

1/1/2008

8/7/2008

 

can anybody tell me whats wrong. i cannot display the result above

 

  • 2 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.