date format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    date format

    hi there i am having a prob with the date format i have an inventory application in which i have to make a SALES BILL ENTRY FORM i ma using php & mysql for storing the fields and for the back-end programming
    i am using the following code for the date with the
    format "month-date-year"
    Code:
    <?
    	$date=date("m-j-Y");
    ?>
    [html]
    <tr>
    <td class="add">Sal e Date:</td>
    <td valign="middle" ><input name="sel_date" id="sel_date" readonly="true" type="text" size="25" value="<?=$date ?>" class="addinp"> </td>
    </tr>
    [/html]
    but the problem is that when i try to vie the details in the sale detail page it shows the folllowing values
    Code:
    0000-00-00
    thanks for any any help in this regard
    Omer.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I cannot see any MySQL in the code you show. So this is NOT a MySQL problem, but a PHP one. Thread will be moved to PHP forum.

    I cannot see any problem with the code you show (unless it is not all the code involved). One reason I can think of is that your server does not accept the abbreviation <? to start PHP code. Use <?php instead.

    Ronald

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by omerbutt
      hi there i am having a prob with the date format i have an inventory application in which i have to make a SALES BILL ENTRY FORM i ma using php & mysql for storing the fields and for the back-end programming
      i am using the following code for the date with the
      format "month-date-year"
      Code:
      <?
      	$date=date("m-j-Y");
      ?>
      [html]
      <tr>
      <td class="add">Sal e Date:</td>
      <td valign="middle" ><input name="sel_date" id="sel_date" readonly="true" type="text" size="25" value="<?=$date ?>" class="addinp"> </td>
      </tr>
      [/html]
      but the problem is that when i try to vie the details in the sale detail page it shows the folllowing values
      Code:
      0000-00-00
      thanks for any any help in this regard
      Omer.

      Hi Omer,

      You said that you were getting data from a MySQL database. however, the code snippet showews no such thing so I'm not sure where the data is coming from. The definition of $date you supply should simply give the current date in the format of month number with leading zeroes, day number without leading zeroes and a four digit year.

      If you want to get the data out of the database in the correct format then take a look at date_format.

      You can use this when you retreive the data from the table in question.

      The only thing I can see 'wrong' with your code is your inline PHP, change;
      [html]
      value="<?=$date ?>"
      [/html]
      to
      [html]
      value="<?php $date ?>"
      [/html]

      That should sort you out I think.

      Personally I don't like mixed code like that and would do it all in php:
      [php]
      <?php
      $date=date("m-j-Y");

      echo '<tr>
      <td class="add">Sal e Date:</td>
      <td valign="middle" ><input name="sel_date" id="sel_date" readonly="true" type="text" size="25" value="' . $date . '" class="addinp"> </td>
      </tr>';
      ?>
      [/php]
      I hope that helps you out.
      Cheers
      nathj

      Comment

      • omerbutt
        Contributor
        • Nov 2006
        • 638

        #4
        Originally posted by nathj
        You said that you were getting data from a MySQL database. however, the code snippet showews no such thing so I'm not sure where the data is coming from. The definition of $date you supply should simply give the current date in the format of month number with leading zeroes, day number without leading zeroes and a four digit year.
        nathj actually if i try to write
        [html]
        $date=date()
        [/html]
        it gives me error regarding the missing parameters in date
        Code:
        Warning: date() expects at least 1 parameter, 0 given in D:\Server\htdocs\ASHAR\ad_sale_frm.php on line 10
        The only thing I can see 'wrong' with your code is your inline PHP, change;
        [html]
        value="<?=$date ?>"
        [/html]
        to
        [html]
        value="<?php $date ?>"
        [/html]
        well these are all the different ways to write its not a mistake you can even write it like
        Code:
        value=<?echo $date;?>
        but you are not getting the problem its not with displaying the date in the form field its my mistake to not elaborate the problem OK NOW
        i have the prob in the inserting part the page where i am inserting the values into the MySQL i think so because the date isnt saved into the data base in the format i want to save it here is the code for that page
        Code:
        $hostname="localhost";
        	$username="root";
        	$password="66456";
        	$database="db1";
        	
        	$conn_stk = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
        	mysql_select_db($database, $conn_stk);
        	
        	$billno=$_POST["bill_no"];
        	$seldate=$_POST["sel_date"];
        	$cname=$_POST["cust_name"];
        	$mop=$_POST["m_o_p"];
        	$cper=$_POST["con_per"];
        	$cno=$_POST["con_no"];
        	$prd=$_POST["prd"];
        	$codeno=$_POST["code_no"];
        	$prt=$_POST["part"];
        	$stkavl=$_POST["stk_avl"];
        	$uprc=$_POST["u_prc"];
        	$stkreq=$_POST["stk_req"];
        	$tprc=$_POST["t_prc"];
        
        $sqlAS="insert into sale_rec(Bill_no,Bill_date,Cust_name,Mop,Con_per,Con_no,Code_no,Prt_no,Stk_avl,Stk_req,U_prc,T_prc,Prd) 
        	values('$billno','$seldate','$cname','$mop','$cper','$cno','$codeno','$prt','$stkavl','$stkreq','$uprc','$tprc','$prd')";
        	$resAS=mysql_query($sqlAS) or die(mysql_error().'<br />'.$sqlAS);
        	echo "The Bill Has been successfully added ";
        i hope i elaborated my problem this time sorry to annoy you people if did [:)]
        thanks for any help in advance,
        regards,
        Omer.

        Comment

        • nehas
          New Member
          • Jan 2008
          • 13

          #5
          Originally posted by omerbutt
          hi there i am having a prob with the date format i have an inventory application in which i have to make a SALES BILL ENTRY FORM i ma using php & mysql for storing the fields and for the back-end programming
          i am using the following code for the date with the
          format "month-date-year"
          Code:
          <?
          	$date=date("m-j-Y");
          ?>
          [html]
          <tr>
          <td class="add">Sal e Date:</td>
          <td valign="middle" ><input name="sel_date" id="sel_date" readonly="true" type="text" size="25" value="<?=$date ?>" class="addinp"> </td>
          </tr>
          [/html]
          but the problem is that when i try to vie the details in the sale detail page it shows the folllowing values
          Code:
          0000-00-00
          thanks for any any help in this regard
          Omer.

          The problem is only this much omerbutt that in mysql date format is yyyy-mm-dd and you have to supply in same format otherwise any other format data will not be accepted by mysql and hence you see "0000-00-00" this value in the database . Just be strict about format will typing in html and you will get it. If you need any further help please feel free to contact .

          Comment

          • omerbutt
            Contributor
            • Nov 2006
            • 638

            #6
            Originally posted by nehas
            The problem is only this much omerbutt that in mysql date format is yyyy-mm-dd and you have to supply in same format otherwise any other format data will not be accepted by mysql and hence you see "0000-00-00" this value in the database . Just be strict about format will typing in html and you will get it. If you need any further help please feel free to contact .
            yeah nehas you are write about it but i want it to be stored in the format
            d-m-y
            i have used this query too but it still not working and giving me error
            Code:
            $sqlAS="insert into sale_rec(Bill_no,Bill_date,Cust_name,Mop,Con_per,Con_no,Code_no,Prt_no,Stk_avl,Stk_req,U_prc,T_prc,Prd) 
            	values('$billno',DATE_FORMAT('$seldate','USA'),'$cname','$mop','$cper','$cno','$codeno','$prt','$stkavl','$stkreq','$uprc','$tprc','$prd')";
            have swapped he statement DATE_FORMAT('$s eldate','USA') to DATE_FORMAT('US A','$seldate') also but it still gives me the same error the date i am posting the date from a form and it is properly posted into this page and is showing the value in the variable $seldate
            but i am recieving the following error
            Code:
                  Column 'Bill_date' cannot be null
                  insert into sale_rec(Bill_no,Bill_date,Cust_name,Mop,Con_per,C  on_no,Code_no,Prt_no,Stk_avl,Stk_req,U_prc,T_prc,P  rd) values('1007',DATE_FORMAT('02-23-2008','USA'),'sameeer','CHEQUE','oemr','0321','100  0','CSV-4456','13','1','500','500','WATER_FILTER')

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Do you have to use DATE_FORMAT?
              Can't you just insert it as you do with any other string..?

              Comment

              • omerbutt
                Contributor
                • Nov 2006
                • 638

                #8
                Originally posted by markusn00b
                Do you have to use DATE_FORMAT?
                Can't you just insert it as you do with any other string..?
                of course i could if i had the format for the field of VarChar in the mysql database :)
                but i have it the date format so wot u think now how sholu i be doing it
                thanks for any help in advance,
                Omer.

                Comment

                Working...