Author Topic: MySQL + Date + php  (Read 3021 times)

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
MySQL + Date + php
« on: March 02, 2006, 01:43:44 PM »
I have a db, and I realized today when I was sorting dates, stored in the db as a varchar, in the form of 2/27/2005, that they werent getting sorted properly.

I want to perform a query on the date to get the 20 most recent entries of the db according to the date received column.

I found the php function strtotime which converts the date into seconds.  Is it best to convert the time into seconds using this function, store it in the db in that maner, and when I need to print the date I use strtotime again to format it properly?

Thanks

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
MySQL + Date + php
« Reply #1 on: March 02, 2006, 02:06:36 PM »
I'm not sure why you're storing it as a varchar... you should be storing it as a date/time or whatever date format the database provides.

But yeah, the best way is to store it in that manner and convert it into seconds on the fly for display.

My method:
Code: [Select]
// $updated is an extract()-ed variable from a recordset