Welcome Guest, Not a member yet? Register   Sign In
Date format
#1

[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);
      echo $nd;
      $query_str="UPDATE contest SET Deadline = $nd where Contest_Id=$id";
     $this->db->query($query_str);


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 ?

#2

[eluser]SkiOne[/eluser]
What version of PHP, what database are you using?
#3

[eluser]TWP Marketing[/eluser]
Also tell us what is the format of the date field in your db table?
#4

[eluser]Kentish[/eluser]
that will be php5.3, mysql and format of date field, is date
#5

[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
#6

[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);
#7

[eluser]Kentish[/eluser]
Many thanks Smile




Theme © iAndrew 2016 - Forum software by © MyBB