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

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.