Jump to content

NOW (), Datetime & Varchar Scramble


adriscoll

Recommended Posts

Hello,

 

I have a query that displays a list of events for the year, and am in need of guidance on how to have it only show events that are >= today's date. 

 

The 'date' is inserted into the table as a varchar field from javascript code.  There was an old blog post about doing something like....

 

SELECT * FROM calendar WHERE `date` >= NOW() ORDER BY date ASC LIMIT 5

 

I seem to have trouble in that i believe NOW() will only work with proper datetime entries as opposed to my varchar setup.

 

any help navigating this would be great.

Link to comment
Share on other sites

You didn't show what your date format was.

 

You should store dates using the DATE data type, that's what it is for. Doing so will allow you to directly sort, order, and do greater-than/less-than comparisons on the values. Your data will also take up less storage and your queries will execute faster and will easier to write.

Link to comment
Share on other sites

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.