English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The date field is input in a field on my form as:

DD/MM/YYYY

But I need it formatting before I submit t to the database using php. The format I need is YYYY-MM-DD

How can I do this?

2007-08-21 05:37:29 · 5 answers · asked by jeff lemon 1 in Computers & Internet Programming & Design

5 answers

Much simpler than the above posts...

date('Y-m-d', strtotime($_POST['submitdate'] ) );

what this does is converts the date submitted on your form to a timestamp which the date function can use to format it however it needs to be.

2007-08-22 05:01:58 · answer #1 · answered by sheepbalz 3 · 0 1

Above is right if you need the current date, if this is the case you could also just do a NOW() or format the now for what you need DATE_FORMAT(NOW(), '%Y-%m-%d') (which is what I would go with so that you don't need to validate information or do alot of unnecessary functions.

if not
$inputtedDate = $_GET['inputtedDate'];
$year = substr($inputtedDate, 6); //gets the character indexed at 6 and beyond
$month = substr($inputtedDate, 3, 2); //gets the 2 characters starting with the index of 3
$day = substr($inputtedDate, 0, 2); //get the 2 characters indexed at 0
$formattedDate = $year . '-' . $month . '-' . $day;

2007-08-21 12:58:42 · answer #2 · answered by Big D 4 · 0 1

Go back to college, man! You have asked over 20 questions here, all of which you should know if you were not so lazy!

2007-08-21 13:10:24 · answer #3 · answered by just "JR" 7 · 2 0

$dbDate = date('Y-m-d', $formDate)

// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, n, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month
$today = date("H:i:s"); // 17:16:17
?>

2007-08-21 12:53:05 · answer #4 · answered by Doyzer 2 · 0 2

date('Y-m-d');
?>

2007-08-21 12:41:27 · answer #5 · answered by Terence P 1 · 0 0

fedest.com, questions and answers