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..
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..
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
Nice thank u..!!
can u tell how to do vice versa of it..
i mean convert 2009-12-31 19:09:03 to 20091231190903
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";
}
}
?>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.