Jump to content

Does CURDATE work with UNIX time in MySQL?


CGRRay

Recommended Posts

I have a table where the dates are stored in UNIX timestamp format. I'm trying to use the CURDATE term for a select query but it isn't working. Does CURDATE work with the UNIX time stamp?
Any help is appreciated.
Here's the query:
select first_name, last_name, date_expires, title
from cl_member, `user`, cl_chapter
where cl_member.user_id=`user`.user_id
and cl_member.chapter_id=cl_chapter.chapter_id
and cl_member.chapter_id=14
and month(date_expires)=month(CURDATE())
ORDER BY last_name
Link to comment
Share on other sites

oh whoops unix timestamp... i think you want to use one of these functions:

from mysql timestamp to unix: UNIX_TIMESTAMP(mysqltimestamp)
from unix timestamp to mysql: FROM_UNIXTIME(unixtimestamp)

so in your compare statement use:
month( FROM_UNIXTIME(unixtimestamp) )=month(NOW())

i would just use php though if it were my choice to convert date info...
date('Y' ,$unixTimestampFieldFromMysql)
date('m' ,$unixTimestampFieldFromMysql)
etc
Link to comment
Share on other sites

Well, if you're asking, create a new column of the desired type, issue the update statement to copy them over, then drop the old column (and rename the new one to the old one).  Ideally, the application will have been inserting valid SQL dates the whole time, and you won't have to
change anything else.
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.