Changing the Date Format in PhpMyAdmin DB
Hi:
My PhpMyAdmin DB demands that the date format in the date column be: yyyy-mm-dd. Is there any way to change that format? For example to dd-mm-yyyy?
Thank you for your attention
Hi:
My PhpMyAdmin DB demands that the date format in the date column be: yyyy-mm-dd. Is there any way to change that format? For example to dd-mm-yyyy?
Thank you for your attention
no, you cannot change the format that the database requires.
you can change how the date is displayed on the page though by using the date() and strtotime() functions:
<?php echo(date("d-m-Y", strtotime($row_recordsetName['statecode']))); ?>
Jason:
Thank you for your reply. Could you kindly tell me where should that line of code go? The top of the page? Where?
Thank you for your attention.
Jason:
Please disregard my previous entry. I already got it.
Thank you for your attention
Jason:
Your line of code works perfectly well. Would it be possible to do the same operation in reverse? Meaning entering the date in dd-mm-yyyy format and turning it into the yyyy-mm-dd DB format before storing?
Thank you for your attention
Jason:
I changed the Date-entry format in DW to dd.mm.yyyy, but it gets stored in a scrambled line of numbers. Is there any way to change the Date entry format to dd.mm.yyyy and have it store and display correcty afterwards?
Thank you for your attention
the format stored in the database must by yyyy-dd-mm
you can use the date() and strtotime() functions to allow you to enter the date using dd.mm.yyyy format and have it stored correctly, for exaample add code similar to this at line one of the data assist pages:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
$_POST['dateElement'] = "".((isset($_POST["dateElement"]))?date("Y-m-d", strtotime($_POST["dateElement"])):"") ."";
}
?>
and then use code similar to this to convert it back when displaying:
<?php echo(date("d.m.Y", strtotime($row_recordsetName['dateColumn']))); ?>
jason:
Thank you for your reply.
I tried entering the code you suggested at the top of the data-entry page, but the dates are still stored in a scrambled manner, and so ar they when diaplayed in the results, details, etc., pages.
Attached please find a copy of the page where the dates are entered and of the results page where they are displayed.
Any suggestions?
what do you mean exactly by "scrambled manner"? what is the data type for the column in the datebase, you should be using date.
the code i gave was an example, you need to substitute the correct form elements names. In your form, the data element is named "dateReg", so the code at the top of the page should be:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
$_POST['dateReg'] = "".((isset($_POST["dateReg"]))?date("Y-m-d", strtotime($_POST["dateReg"])):"") ."";
}
?>
jason:
OK. Since I have 3 different date fields in the data entry form, should I add three lines of code similar to the one you sent? Or can I add the other 2 date fields after "dateReg"?
Thank you for your attention
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.