CGRRay Posted November 10, 2006 Share Posted November 10, 2006 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, titlefrom cl_member, `user`, cl_chapterwhere cl_member.user_id=`user`.user_idand cl_member.chapter_id=cl_chapter.chapter_idand cl_member.chapter_id=14and month(date_expires)=month(CURDATE())ORDER BY last_name Quote Link to comment https://forums.phpfreaks.com/topic/26844-does-curdate-work-with-unix-time-in-mysql/ Share on other sites More sharing options...
arianhojat Posted November 10, 2006 Share Posted November 10, 2006 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.blahWHEREmonth(date)=month(NOW())not sure what your problem is Quote Link to comment https://forums.phpfreaks.com/topic/26844-does-curdate-work-with-unix-time-in-mysql/#findComment-122772 Share on other sites More sharing options...
arianhojat Posted November 10, 2006 Share Posted November 10, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/26844-does-curdate-work-with-unix-time-in-mysql/#findComment-122786 Share on other sites More sharing options...
fenway Posted November 10, 2006 Share Posted November 10, 2006 The real question is why you're not storing them as dates ... you can FROM_UNIXTIME() them on the way in. Quote Link to comment https://forums.phpfreaks.com/topic/26844-does-curdate-work-with-unix-time-in-mysql/#findComment-122805 Share on other sites More sharing options...
CGRRay Posted November 10, 2006 Author Share Posted November 10, 2006 It's a good question. we inherited the database that way. and i don't know how to go about converting them to mysql. Quote Link to comment https://forums.phpfreaks.com/topic/26844-does-curdate-work-with-unix-time-in-mysql/#findComment-122909 Share on other sites More sharing options...
fenway Posted November 12, 2006 Share Posted November 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/26844-does-curdate-work-with-unix-time-in-mysql/#findComment-123345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.