Jump to content

Does CURDATE work with UNIX time in MySQL?


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
i have a database field named date set to TIMESTAMP type,
and a row in that table whose value is '2007-11-07 12:15:35'

This Query works and returns that one row (with CURDATE() or NOW() ):
SELECT *, month(NOW()) FROM intranet.blah
WHERE
month(date)=month(NOW())


not sure what your problem is
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
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.
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.