DATES

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

DATES

Post by gurjit »

hi all,

i can receive dates in the format day/month/year. However the format they are stored vary. i want to be able to convert these dates to mysql format Y-m-d.

The diifferent formatis i can get for day/month/year can be:

28/2/04
28/02/04
28/02/2004
28/2/2004

many more depending on the date. How can i simply just convert what ever format to mysql format Y-m-d.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

function convert_date($date) {
    $date_arr = explode('/', trim($date));
    return date("Y-m-d", mktime(0, 0, 0, $date_arr[1], $date_arr[0], $date_arr[2]));
}
Post Reply