943,747 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1502
  • PHP RSS
Mar 5th, 2008
0

Time Stamp Help

Expand Post »
I am using current_timestamp and it works great but when I output the data onto a php page it looks like this:

2008-03-05 18:05:44

Anyone know how I can make it look like this?

03-05-2008 18:05:44
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Morty222 is offline Offline
29 posts
since Jan 2008
Mar 6th, 2008
0

Re: Time Stamp Help

Use the date() function: http://php.net/date

php Syntax (Toggle Plain Text)
  1. $time = time();
  2. $date = date('d-m-L H:i:s' , $time);
  3.  
  4. echo $date; // 03-05-2008 18:05:44
Reputation Points: 16
Solved Threads: 1
Newbie Poster
fert is offline Offline
9 posts
since Feb 2008
Mar 6th, 2008
0

Re: Time Stamp Help

Here,I made a function just for you using explode function:

php Syntax (Toggle Plain Text)
  1. //$var is your timestamp...
  2. function x($var)
  3. {
  4. list($date,$time)=explode(" ", $var);
  5. list($year,$month,$day)=explode("-",$date);
  6. $newdate=$month."-".$day."-".$year." ".$time;
  7. return $newdate;
  8. }

Enjoy!!!
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Mar 6th, 2008
0

Re: Time Stamp Help

php Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. //old time
  4. $old_time = '2008-03-05 18:05:44';
  5.  
  6. //convert to UNIX timestamp
  7. $timestamp = strtotime($old_time);
  8.  
  9. //fetch new format
  10. $new_time = date('m-d-Y H:i:s' , $timestamp);
  11.  
  12. //output new time
  13. echo $new_time;
  14. ?>
Reputation Points: 14
Solved Threads: 14
Junior Poster in Training
johnsquibb is offline Offline
84 posts
since Nov 2007
Mar 6th, 2008
0

Re: Time Stamp Help

Click to Expand / Collapse  Quote originally posted by fert ...
Use the date() function: http://php.net/date

php Syntax (Toggle Plain Text)
  1. $time = time();
  2. $date = date('d-m-L H:i:s' , $time);
  3.  
  4. echo $date; // 03-05-2008 18:05:44
'L' returns 1 if it is a leap year or 0 if it is not. Use 'Y' for 4-digit year.
Reputation Points: 14
Solved Threads: 14
Junior Poster in Training
johnsquibb is offline Offline
84 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Choosing Symfony , Zend Framework, CakePHP
Next Thread in PHP Forum Timeline: PHPEclipse installation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC