Date format |
[eluser]Kentish[/eluser]
Hello, i need some help to format a date. I need yesterday's date to be saved in my db in the format d/m/Y. When i use the following : Code: $nd = date("m/d/Y", time() - 60 * 60 * 24); The appropriate result is output, i.e : 08/11/2012 However when i check in the database, i see 0.000361467558151093. How can i save the date as 08/11/2012 ?
[eluser]TWP Marketing[/eluser]
Also tell us what is the format of the date field in your db table?
[eluser]Kentish[/eluser]
that will be php5.3, mysql and format of date field, is date
[eluser]SkiOne[/eluser]
You need to store the date in the mysql datetime format YYYY-MM-DD HH:MM:SS So to get your date to change format use the php datetime object http://us.php.net/manual/en/book.datetime.php
[eluser]TWP Marketing[/eluser]
[quote author="Kentish" date="1344792273"] ... I need yesterday's date to be saved in my db in the format d/m/Y. ... [/quote] It doesn't NEED to be saved in the format you wish to have displayed and in fact this will cause a lot of headache if you try to force the db field to match your output display format. Change the format of your field to "datetime" (as mentioned earlier). When you read the field from the db, display it in whatever format you wish. Using the php date() method. Code: echo date('m/d/Y', $mydate);
|
Welcome Guest, Not a member yet? Register Sign In |