Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.