--- In [email protected], James Keeline <[EMAIL PROTECTED]> wrote:
>
> --- Tedit kap <[EMAIL PROTECTED]> wrote:
> 
> > I would like to modify the dae display format, for the dates 
stored in my
> > database. 
> > It is stored like this: 2008-07-01
> > I want to print as: July, 1st
> > Now I wrote something as below, but it displays Dec 31st instead 
of July 1st.
> > (And in my database Dec31 is nowhere anyway). Please tell me how 
to fix.
> > Here is the relevant part of code:
> > while ($row = mysql_fetch_array($query)) {
> > $c1=$row['date'];
> > $c=date('F jS',$c1);
> > echo"<p class='title1'>" . $c."<br/>". $row['title'] . "</p>" ; }
> > Thanks
> 
> 
> You obviously don't want to change the way the dates are stored in 
the database
> but you might want to change the way they are displayed either with
> command-line queries or in your PHP scripts.
> 
> You can use the date_format() function in MySQL to control the 
display of the
> date/time in a MySQL query.  This can carry over to the value sent 
to your PHP
> script.  It is often a good way to work with dates if you have them 
before 1970
> (eg birthdates) or after 2030.  MySQL can handle dates from 1000-01-
01 to
> 9999-12-31.  This range is much longer than the roughly 1970-2030 
range
> afforded to PHP and most computer operating systems.
> 
> You found the PHP function called date() and this is good.  
However, it is
> worth reading the documentation which identifies the second 
parameter to be a
> number of seconds since the epoch date for that server (usually 
1970-01-01
> 00:00:00).  The limited number of bits granted for this is why 
there's a
> maximum value in 2030 or thereabouts.
> 
> You should not play games with slicing and dicing strings to get 
the values
> out.  That might be necessary in some languages.  However, PHP has 
some more
> powerful tools for working with this.  In this case, you could use 
strtotime()
> to convert a date/time expression to the integer number of seconds 
since 1970
> that date() wants to see:
> 
> $c1 = $row['date'];
> $c  = date('F jS', strtotime($c1));
> echo "<p class='title1'>" . $c."<br/>". $row['title'] . "</p>" ;
> 
> Remember the limits of the date range for the PHP expressions.  You 
may want to
> use MySQL's date_format() function.
> 
> James
>
Thanks James this is what I was looking for....

Reply via email to