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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.