View Single Post
Old 10-15-2012, 10:14 AM   PM User | #4
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Quote:
Originally Posted by nani_nisha06 View Post
HI frnds,

can any one please help me to post dd-mm-yyyy date format to Mysql which is yyyy-mm-dd.


I am struggling lot to solve this but could not able to success it....

my php code is :


Code:
<?php
session_start();
$host="localhost"; // Host name 
$username="#############"; // Mysql username 
$password="##########"; // Mysql password 
$db_name="#########"; // Database name 
$tbl_name="#########"; // Table name 
$myusername = $_SESSION['myusername']; //user who updating
$con = mysql_connect("$host","$username","$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name(`Creation_Date`, `Resolved_Date`, `Analyst`, `Email_Address`, `Status`, `Mail_Sent`, `Call_Made`, `Doc_verf`, `Change2analyst`, `Change3analyst`) 

VALUES 

('$_POST[requiredCD]','$_POST[requiredRD]','$myusername','$_POST[requiredEmail]','$_POST[Status]','$_POST[MailSent]','$_POST[Call]','$_POST[Docverf]','$_POST[Analyst2]','$_POST[Analyst3]')";

$result1=mysql_query($sql)or die(mysql_error());
{
header("location:new_user.php") or die("record not inserted");
}
mysql_close();
?>
Use strtotime which converts the time you give it to a unix timestamp which can then be easily coverted to any date format you want using the date() function.

Like this:
PHP Code:
<?php
//E.g
$date1 '$_POST['requiredCD']'//$Date variable now has date like 23-09-1994

$date_tstamp strtotime($date1);

$date_converted date('Y-m-d'$date_tstamp//Now contains 1994-09-23
The above could have been done with the below one-line code:
PHP Code:
<?php

$date_converted 
date('Y-m-d'strtotime($_POST['requiredCD']));  //$date_coverted contains 1994-09-23
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk

Last edited by Redcoder; 10-15-2012 at 10:16 AM..
Redcoder is offline   Reply With Quote