date manipulation

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
serap
Forum Commoner
Posts: 31
Joined: Thu Jan 15, 2004 5:10 pm

date manipulation

Post by serap »

I have a problem with the dates, I just wonder if I can do something about it or wether it is a server issue:

all the dates we insert is inserted in the US format yyyy-mm-yy.

Can we insert it in the dd-mm-yyyy format just by using the DATE_FORMAT() withut needing to change the server setings (we dont have access to it).
If not we will need format it before INSERTING and after QUERYING each time and that would be...not good???

thanks,
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Don't format it when inserting - it should be put into a proper date column with the proper format. Only change the format when you select the date for display, that's not a prob.

Mac
serap
Forum Commoner
Posts: 31
Joined: Thu Jan 15, 2004 5:10 pm

Post by serap »

what if the users so not want to write it in the yyyy-mm-dd format then I have to?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

dont let them write it. On the form use three separate inputs then concatenate them before inserting
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Ps. YYYY-MM-DD is NOT the US Date Format, it is The international standard date notation. Americans prefer MM-DD-YY.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Sweds likely use YYMMDD. So even there is a difference, slight, but still.

As magicrobotmonkey mention, the use of more than one form-field might be interesting, if that helps you. Be sure to check the [php_man]checkdate[/php_man]() function as well. It might be useful.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I found the solution searching here at home last night. I don't have the link, but it was something like:

Code: Select all

<?php

$getDate = mysql_query("SELECT DATE_FORMAT('theDate', '%c-%e-%y') AS theDate FROM the_table";
$row = mysql_fetch_array($getDate, MYSQL_ASSOC);
$newDate = $row['theDate'];
echo $newDate;

?>
Something like that... I'll take a looksy when I get home and if it is wrong I'll correct myself.

:)
Post Reply