Jump to content

problem with DATE field format, ordering data


glennn.php

Recommended Posts

 

I originally created a db with a particular field (ck_pt) that holds a date as VARCHAR(15) - now they want the output sortable by that field DESC...

 

the dates that are in there are like such 7/25/08 - when i switch the TYPE to DATE, the vaalues go to 07-25-2008, or perhaps 25-07-2008 - i dunno, but SOME of the values go to 00-00-0000 (GOD i'm glad i backed it up).

 

why am i losing some of the values, and what can i do about getting these fields converted properly and queried into a page where %d/%m/%y will be correctly ordered, 2008 before 2009, of course...?

 

i really appreciate your help.

 

GN

Link to comment
Share on other sites

Just changing the column type does not change the data in it. You will need to add a new column of the correct type and copy/format the existing values into the new column. Once you have all your code working with the new column, you can delete the old column. You an use the mysql STR_TO_DATE() function in a single UPDATE query (with no WHERE clause) to copy and format the existing values into the new column.

Link to comment
Share on other sites

Just changing the column type does not change the data in it.

 

hate to disagree, but this is in fact exactly what happened. some of the dates were changed to 00-00-0000. promise. wouldn't lie to you.

I think PFMaBiSmAd meant that it won't STR_TO_DATE() it for you.

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.