Normal date to Unix?

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
irmakerol
Forum Newbie
Posts: 1
Joined: Sat Apr 12, 2003 8:33 pm

Normal date to Unix?

Post by irmakerol »

Hello all,

I have a form field where users enter the date as dd-mm-YYYY..
What do I need to do to insert this info into a MySql database in Unix timestamp(10) format?

Please urgent help, sleepless for days and night because of this nightmare.

Thanks :twisted:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you might try

Code: Select all

<?php
ini_set('display_errors', TRUE);
$userinput = '13-04-2003';
$udate = sscanf($userinput, '%d-%d-%d');
if (strlen($udate[0]) > 0 && strlen($udate[1]) && strlen($udate[2])
	&& checkdate($udate[1], $udate[0], $udate[2])
	)
{
	$dateForMysql = $udate[2] .'-'. $udate[1] .'-'. $udate[0];
	echo $dateForMysql;
	
}
else
	echo 'invalid date';
?>
Post Reply