Current location: Hot Scripts Forums » Programming Languages » PHP » how to convert a numerical date into a string date?


how to convert a numerical date into a string date?

Reply
  #1 (permalink)  
Old 05-12-08, 03:39 AM
moroose moroose is offline
Newbie Coder
 
Join Date: May 2007
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
how to convert a numerical date into a string date?

Hi all,
I'd like to convert a retrieved mysql datetime date format into a human readable format date in php.
PHP Code:

Start Date2007-05-11 20:32:17

End Date
2008-11-12 00:17:54 
I know i can use the mysql date_format but in this script i dont want to create a select statement.I got the above result via sessions from previous pages.

can anyone please help with this?
thank you in advance
Reply With Quote
  #2 (permalink)  
Old 05-12-08, 03:52 AM
BurakUeda BurakUeda is offline
Newbie Coder
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
ignore this.. will edit the post with a solution....
__________________
http://humo.org
Just another general discussion forum
Reply With Quote
  #3 (permalink)  
Old 05-12-08, 04:01 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
use the strptime function:
PHP Code:

$format "%Y-%d-%m %H:%M:%S";
print_r ($date$format); 
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #4 (permalink)  
Old 05-12-08, 07:36 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You could do it like this:

PHP Code:

<?php
$_SESSION
["start_date"]="2007-05-11 20:32:17";
$_SESSION["end_date"]="2008-11-12 00:17:54";
echo 
date("M d, Y H:i:s",strtotime($_SESSION["start_date"])).
     
"<br />".
     
date("M d, Y H:i:s",strtotime($_SESSION["end_date"]));
?>
Here I split the date and time and display it in a table.

PHP Code:

<style>
td
{
 padding-left:5px;
 padding-right:5px;
 }
</style>
<?php
$_SESSION
["start_date"]="2007-05-11 20:32:17";
$_SESSION["end_date"]="2008-11-12 00:17:54";
echo 
"<table border=1>
       <tr><th colspan=2>Start</th><th colspan=2>End</th></tr>
       <tr><th>Date</th><th>Time</th><th>Date</th><th>Time</th></tr>
       <tr><td>"
.date("M d, Y",strtotime($_SESSION["start_date"]))."</td><td>".date("H:i:s",strtotime($_SESSION["start_date"]))."</td>
       <td>"
.date("M d, Y",strtotime($_SESSION["end_date"]))."</td><td>".date("H:i:s",strtotime($_SESSION["end_date"]))."</td></tr>
      </table>"
;
?>
__________________
Jerry Broughton

Last edited by job0107; 05-12-08 at 08:01 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting date-string to Date object UnrealEd Everything Java 4 05-15-07 06:20 PM
problem returning interest in bankaccount program psi3000 Everything Java 6 03-27-06 01:14 PM
BankAccount object oreinted help psi3000 Everything Java 6 03-16-06 10:07 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 07:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.