Jump to content

[SOLVED] SQL sorting by date


drummer101

Recommended Posts

Well I didn't do such a great job designing one of my code snippets, and ended up storing the date in plain text, e.g. 1/10/2008, what would be the best way to store dates in the DB so they are easy to manipulate.

 

I've created a new field on the table, type = date and I'm curious what I would use on the PHP side to properly format the input for the database.

 

the date type is formatted yyyy-mm-dd, would date(Y-m-d) be the correct way to go about this or is there an easier way? Once stored, would explode() be the optimal way to get the date back into a mm-dd-yyyy format?

Link to comment
https://forums.phpfreaks.com/topic/85495-solved-sql-sorting-by-date/
Share on other sites

Well I didn't do such a great job designing one of my code snippets, and ended up storing the date in plain text, e.g. 1/10/2008, what would be the best way to store dates in the DB so they are easy to manipulate.

 

I've created a new field on the table, type = date and I'm curious what I would use on the PHP side to properly format the input for the database.

 

the date type is formatted yyyy-mm-dd, would date(Y-m-d) be the correct way to go about this or is there an easier way? Once stored, would explode() be the optimal way to get the date back into a mm-dd-yyyy format?

Hi drummer,

 

First thing when ever you are saving your date use the data type Date or datetime.And i will suggest you to use date_format() function of mysql while saving the date in the required format or while retrieve.

 

Regards

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.