Skip to content

Instantly share code, notes, and snippets.

@sivaprabug
Created February 12, 2013 08:20
Show Gist options
  • Save sivaprabug/4760944 to your computer and use it in GitHub Desktop.
Save sivaprabug/4760944 to your computer and use it in GitHub Desktop.
Change the date format and store in DB
<?php
$conn=mysql_connect("localhost","root","kirti123") ;
if(!$conn)
{
die('connection Error' . mysql_error());
}
// DATE CONVERSION
$date=$_POST['add_date']; // get the date value in post method
$date_array = explode("-",$date); // split the array
$var_month = $date_array[0]; //month segment
$var_day = $date_array[1]; //day seqment
$var_year = $date_array[2]; //year segment
$new_date_format = "$var_year-$var_month-$var_day"; // join them together
mysql_select_db('test',$conn);
$sqll="INSERT INTO register(name, nickname, mbno, add_date) VALUES ('$_POST[name]', '$_POST[nickname]', '$_POST[mbno]','$new_date_format')";
if(!mysql_query($sqll,$conn))
{
die('Error in Connection' .mysql_error());
}
echo "Added Successfully";
mysql_close($conn)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment