Jump to content


Photo

How to compare dates in mysql query


  • Please log in to reply
2 replies to this topic

#1 t_machine

t_machine
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 25 April 2006 - 06:51 PM


hi, I am wondering if anyone can help me with this date problem. I have a database that stores username and date(unix timestamp). I would however like to list all the usernames within the current month. Something like this would be great.

$thismonth = date('m,Y', time()); // 04,2006
"SELECT username FROM TABLENAME WHERE date_added ='$thismonth'

how can i strip the 'date_added' which is in timestamp to month and year so I could compare and list the users within that month. Thanks :)

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 25 April 2006 - 11:06 PM


.... WHERE DATE_FORMAT(FROM_UNIXTIME(date_added), '%m,%Y') = '$thismonth'

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 t_machine

t_machine
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 26 April 2006 - 03:30 PM


Thank you very much :) This works great!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users