Jump to content


Order by date ( display newest item )

  • Please log in to reply
4 replies to this topic

#1 scottrohe

  • Members
  • PipPip
  • Member
  • 28 posts

Posted 05 August 2006 - 11:18 PM

Ok well I have everything right I just need to know WHICH date format I should use when entering the date into the db.
ex; I've tried:
      $date = date('dmy', strtotime($date));
so I get the result of '050806' but when I order that in a sql queue  'ORDER BY date DESC', and i test it by changing the date around on tables, it just doesn't work flawlessly. I was also wanting to add in like a timestamp so if 2 items are added at once, but one is added a second or two later, it's newer and therefore displays ahead of the one added 2 seconds before it.. what would my 'date' variable be? Thanks.

#2 Barand

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

Posted 05 August 2006 - 11:25 PM

Best is 2006-08-06 (Y-m-d) so it is sortable

If you make it a DATETIME type and store the value NOW() into it when you add a record then you will get Y-m-d H:i:s
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


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

#3 nethnet

  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 05 August 2006 - 11:26 PM

Insert them with the MySQL function now().  That inputs a timestamp.  You can always format it when you retrieve it from the database.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#4 scottrohe

  • Members
  • PipPip
  • Member
  • 28 posts

Posted 05 August 2006 - 11:32 PM

thanks  :)

#5 onlyican

  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 05 August 2006 - 11:45 PM

Mysql actually stores dates in the format of Y-m-d H:i:s
Which in translation
2006-08-06 01:45:12
Tell me the problem, I will try tell you the solution

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users