Page 1 of 1

Normal date to Unix?

Posted: Sat Apr 12, 2003 8:33 pm
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:

Posted: Sun Apr 13, 2003 5:56 am
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';
?>