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

date format

omerbutt
100+
P: 638
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"
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     $date=date("m-j-Y");
  3. ?>
  4.  
[html]
<tr>
<td class="add">Sale 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
Expand|Select|Wrap|Line Numbers
  1. 0000-00-00
  2.  
thanks for any any help in this regard
Omer.
Feb 22 '08 #1
Share this Question
Share on Google+
7 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 22 '08 #2

nathj
Expert 100+
P: 938
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"
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     $date=date("m-j-Y");
  3. ?>
  4.  
[html]
<tr>
<td class="add">Sale 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
Expand|Select|Wrap|Line Numbers
  1. 0000-00-00
  2.  
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">Sale 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
Feb 22 '08 #3

omerbutt
100+
P: 638
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
Expand|Select|Wrap|Line Numbers
  1.  
  2. Warning: date() expects at least 1 parameter, 0 given in D:\Server\htdocs\ASHAR\ad_sale_frm.php on line 10
  3.  
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
Expand|Select|Wrap|Line Numbers
  1. value=<?echo $date;?>
  2.  
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
Expand|Select|Wrap|Line Numbers
  1. $hostname="localhost";
  2.     $username="root";
  3.     $password="66456";
  4.     $database="db1";
  5.  
  6.     $conn_stk = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
  7.     mysql_select_db($database, $conn_stk);
  8.  
  9.     $billno=$_POST["bill_no"];
  10.     $seldate=$_POST["sel_date"];
  11.     $cname=$_POST["cust_name"];
  12.     $mop=$_POST["m_o_p"];
  13.     $cper=$_POST["con_per"];
  14.     $cno=$_POST["con_no"];
  15.     $prd=$_POST["prd"];
  16.     $codeno=$_POST["code_no"];
  17.     $prt=$_POST["part"];
  18.     $stkavl=$_POST["stk_avl"];
  19.     $uprc=$_POST["u_prc"];
  20.     $stkreq=$_POST["stk_req"];
  21.     $tprc=$_POST["t_prc"];
  22.  
  23. $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) 
  24.     values('$billno','$seldate','$cname','$mop','$cper','$cno','$codeno','$prt','$stkavl','$stkreq','$uprc','$tprc','$prd')";
  25.     $resAS=mysql_query($sqlAS) or die(mysql_error().'<br />'.$sqlAS);
  26.     echo "The Bill Has been successfully added ";
  27.  
i hope i elaborated my problem this time sorry to annoy you people if did [:)]
thanks for any help in advance,
regards,
Omer.
Feb 23 '08 #4

P: 13
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"
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     $date=date("m-j-Y");
  3. ?>
  4.  
[html]
<tr>
<td class="add">Sale 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
Expand|Select|Wrap|Line Numbers
  1. 0000-00-00
  2.  
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 .
Feb 23 '08 #5

omerbutt
100+
P: 638
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
Expand|Select|Wrap|Line Numbers
  1. $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) 
  2.     values('$billno',DATE_FORMAT('$seldate','USA'),'$cname','$mop','$cper','$cno','$codeno','$prt','$stkavl','$stkreq','$uprc','$tprc','$prd')";
  3.  
have swapped he statement DATE_FORMAT('$seldate','USA') to DATE_FORMAT('USA','$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
Expand|Select|Wrap|Line Numbers
  1.       Column 'Bill_date' cannot be null
  2.       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')
  3.  
Feb 23 '08 #6

Markus
Expert 5K+
P: 6,050
Do you have to use DATE_FORMAT?
Can't you just insert it as you do with any other string..?
Feb 23 '08 #7

omerbutt
100+
P: 638
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.
Feb 25 '08 #8

Post your reply

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