Dates in php part 2 – saving dates to mysql

Came across a problem today where I needed to save value from a jQuery datepicker in dd-mm-yy format to a mysql database date column.

Solution:

$expiry = new DateTime($expiry);
$expiry = date_format ( $expiry, ‘Y-m-d’ );

Then to display it in “normal” format when you retreive it from the db table:

$expiry = new DateTime($expiry);
echo date_format($expiry,’d-m-Y’);

Advertisements
Posted in Php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: