0

hello friends..
i have a value in database in this format..

20091231190903

i want to split in date format in php

2009-12-31 19:09:09:03

how can i do it...?

kindly guide me plz..

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Wraithmanilian
0

to convert String in Date format use the below script:

<?php 

$DATE = "20091231190903";

echo date("Y-m-d H:i:s",(strtotime($DATE)))

?>

Output: 2009-12-31 19:09:03
0

Nice thank u..!!
can u tell how to do vice versa of it..
i mean convert 2009-12-31 19:09:03 to 20091231190903

0

bgold at matrix-consultants dot com had a good solution for this:

When debugging code that stores date/time values in a database, you may find yourself wanting to know the date/time that corresponds to a given unix timestamp, or the timestamp for a given date & time.
The following script will do the conversion either way. If you give it a numeric timestamp, it will display the corresponding date and time. If you give it a date and time (in almost any standard format), it will display the timestamp.
All conversions are done for your locale/time zone.

<?
       while (true)
       {
               // Read a line from standard in.
               echo "enter time to convert: ";
               $inline = fgets(STDIN);
               $inline = trim($inline);
               if ($inline == "" || $inline == ".")
                       break;
               // See if the line is a date.
               $pos = strpos($inline, "/");
               if ($pos === false) {
                       // not a date, should be an integer.
                       $date = date("m/d/Y G:i:s", $inline);
                       echo "int2date: $inline -> $date\n";
               } else {
                       $itime = strtotime($inline);
                       echo "date2int: $inline -> $itime\n";
               }
       }
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.