getting the current date assigned to a database field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharmilah
    New Member
    • Jun 2007
    • 20

    getting the current date assigned to a database field

    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_dat e 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_Serial No" => "",
    "Bkg_FileNo " => "",
    "Bkg_Ent_Na me" => "",
    "Bkg_Ent_Ta n" => "",
    "Bkg_Created_Dt " => "",
    "Bkg_Mod_Dt " => "",
    "Bkg_Mod_Us r" => "",
    "Bkg_BnkId" => "",
    "Bkg_OffId" => "",
    "Bkg_DepId" => "");
    $sql= ' SELECT DATE_FORMAT(cur rent_date, \'%d/%m/%Y\') AS date';
    $res = mysql_query($sq l, $conn) or die(mysql_error ());
    $row["Bkg_Created_Dt "]= mysql_fetch_ass oc($res["date"]) ;[/PHP]

    Thanks in advance
  • bonski
    New Member
    • Jun 2007
    • 53

    #2
    Originally posted by sharmilah
    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_dat e 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_Serial No" => "",
    "Bkg_FileNo " => "",
    "Bkg_Ent_Na me" => "",
    "Bkg_Ent_Ta n" => "",
    "Bkg_Created_Dt " => "",
    "Bkg_Mod_Dt " => "",
    "Bkg_Mod_Us r" => "",
    "Bkg_BnkId" => "",
    "Bkg_OffId" => "",
    "Bkg_DepId" => "");
    $sql= ' SELECT DATE_FORMAT(cur rent_date, \'%d/%m/%Y\') AS date';
    $res = mysql_query($sq l, $conn) or die(mysql_error ());
    $row["Bkg_Created_Dt "]= mysql_fetch_ass oc($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_dat e."')";
    $qry = mysql_query($sq l);


    ok... ^___^

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      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().

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Hi bonski,

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

        Thanks,
        -Ajaxrand

        Comment

        • bonski
          New Member
          • Jun 2007
          • 53

          #5
          Originally posted by ajaxrand
          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 ^_____^

          Comment

          Working...