By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

getting the current date assigned to a database field

P: 20
Hi all

I want to save the current date in a database field in the following format dd/mm/yyyy for example 18/06/2007. How can i do this. The following is code I've used to assign nulls to my values but the value Bkg_created_date should contain the current date in the format mentioned above . I've tried to insert lines code as in lined 13,14,15 but it does not work

[PHP]<?
$row = array(
"Bkg_SerialNo" => "",
"Bkg_FileNo" => "",
"Bkg_Ent_Name" => "",
"Bkg_Ent_Tan" => "",
"Bkg_Created_Dt" => "",
"Bkg_Mod_Dt" => "",
"Bkg_Mod_Usr" => "",
"Bkg_BnkId" => "",
"Bkg_OffId" => "",
"Bkg_DepId" => "");
$sql= ' SELECT DATE_FORMAT(current_date, \'%d/%m/%Y\') AS date';
$res = mysql_query($sql, $conn) or die(mysql_error());
$row["Bkg_Created_Dt"]= mysql_fetch_assoc($res["date"]) ;[/PHP]

Thanks in advance
Jun 19 '07 #1
Share this Question
Share on Google+
4 Replies


bonski
P: 53
Hi all

I want to save the current date in a database field in the following format dd/mm/yyyy for example 18/06/2007. How can i do this. The following is code I've used to assign nulls to my values but the value Bkg_created_date should contain the current date in the format mentioned above . I've tried to insert lines code as in lined 13,14,15 but it does not work

[PHP]<?
$row = array(
"Bkg_SerialNo" => "",
"Bkg_FileNo" => "",
"Bkg_Ent_Name" => "",
"Bkg_Ent_Tan" => "",
"Bkg_Created_Dt" => "",
"Bkg_Mod_Dt" => "",
"Bkg_Mod_Usr" => "",
"Bkg_BnkId" => "",
"Bkg_OffId" => "",
"Bkg_DepId" => "");
$sql= ' SELECT DATE_FORMAT(current_date, \'%d/%m/%Y\') AS date';
$res = mysql_query($sql, $conn) or die(mysql_error());
$row["Bkg_Created_Dt"]= mysql_fetch_assoc($res["date"]) ;[/PHP]

Thanks in advance
hello

save to database.. you will use.. INSERT.. ^__^..

$current_date = date('d/m/Y');

then when inserting...

$sql = "INSERT INTO table_name(some fields...., current_date) VALUES('some values'...., '".$current_date."')";
$qry = mysql_query($sql);


ok... ^___^
Jun 19 '07 #2

pbmods
Expert 5K+
P: 5,821
Heya, sharmilah.

When you save a date in MySQL, you're not actually saving a string in 'Y-m-d' format (in fact, you can even change this format in MySQL's configuration file). Instead, you're saving an integer that represents a number of seconds since January 1st, 1979 (or somewhere around there). For convenience, MySQL displays a more human-readable date format when you SELECT.

I wouldn't worry about how your data is getting saved; just worry about how you format it when you pull it out.

For more information, check out date().
Jun 19 '07 #3

ak1dnar
Expert 100+
P: 1,584
Hi bonski,

You are doing greate job here.Hope this might help you.
Full list of Code Tag Supported Languages

Thanks,
-Ajaxrand
Jun 19 '07 #4

bonski
P: 53
Hi bonski,

You are doing greate job here.Hope this might help you.
Full list of Code Tag Supported Languages

Thanks,
-Ajaxrand
ei ajaxrand..

thanks for giving me the list of those code tag...

bonski ^_____^
Jun 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.