Date format question

This is a discussion on Date format question within the PHP General forums, part of the PHP Programming Forums category; I have a date returned from MySQL in 'YYYY-MM-DD' format, i want to show this date in 'DD/...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-25-2003
Manisha Sathe
 
Posts: n/a
Default Date format question

I have a date returned from MySQL in 'YYYY-MM-DD' format, i want to show
this date in 'DD/MM/YYYY' format using PHP, date() function does the same if
i pass timestamp in int format, but how to convert into int timestamp ?

e.g from '2003-11-25' to '20031125' ? and
Then I believe that i can use date ("d/m/Y", '20031125' ) to the things done
?

Thanks in advance,

regards,
manisha
Reply With Quote
  #2 (permalink)  
Old 11-25-2003
John W. Holmes
 
Posts: n/a
Default Re: [PHP] Date format question

Manisha Sathe wrote:
> I have a date returned from MySQL in 'YYYY-MM-DD' format, i want to show
> this date in 'DD/MM/YYYY' format using PHP, date() function does the same if
> i pass timestamp in int format, but how to convert into int timestamp ?
>
> e.g from '2003-11-25' to '20031125' ? and
> Then I believe that i can use date ("d/m/Y", '20031125' ) to the things done
> ?


No, date() expects a unix timestamp. You can either use

SELECT UNIX_TIMESTAMP(your_column) AS foo FROM Table ...

and then use the value in column 'foo' in date(), or just use
DATE_FORMAT() in your query to retrieve the row already formatted.

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
Reply With Quote
  #3 (permalink)  
Old 11-25-2003
Justin French
 
Posts: n/a
Default Re: [PHP] Date format question

On Tuesday, November 25, 2003, at 01:42 PM, Manisha Sathe wrote:

> I have a date returned from MySQL in 'YYYY-MM-DD' format, i want to
> show
> this date in 'DD/MM/YYYY' format using PHP, date() function does the
> same if
> i pass timestamp in int format, but how to convert into int timestamp
> ?
>
> e.g from '2003-11-25' to '20031125' ? and
> Then I believe that i can use date ("d/m/Y", '20031125' ) to the
> things done
> ?



<?
// the original
$mysql_date = '2003-11-25';

// convert to a unix timestamp (seconds since 1970)
$mysql_date_stamp = strtotime($mysql_date);

// pass $mysql_date_stamp to date() as 2nd parameter
$human_date = date('d/m/Y',$mysql_date_stamp);

echo $human_date;
?>

or simplified:

<?
$original = '2003-11-25';
echo date('d/m/Y', strtotime($original));
?>

Justin French
Reply With Quote
  #4 (permalink)  
Old 11-25-2003
Manisha Sathe
 
Posts: n/a
Default Re: [PHP] Date format question

Thanks to all, it help me a lot

manisha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:48 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0