Converting date From one format to another
iam having the date format stored in da开发者_如何学Gotabase as "20100723"(YYYYMMDD) and how do i convert it into "23-JUL-2010"
$original = "20100723";
$converted = date("d-M-Y", strtotime($original));
See manual: date()
, strtotime()
if php >= 5.3.0
<?php
$date = DateTime::createFromFormat('YYYYMMDD', $dbStoredTime);
echo $date->format('d-M-Y');
strtoupper(date_create("20100723")->format("d-M-Y"))
See the DateTime
class, in particular the DateTime::format
method. date_create
is an alias to the constructor of DateTime
.
Use PHP's strtotime() function, it recognizes the date format in the string and converts it into a Unix timestamp.
$time = strtotime("20100723"); // 1279836000
Then just use date() to convert it back into another string format
echo date("d-M-Y", $time); // 23-Jul-2010
Note that you would have to use strtoupper() to make "Jul" upper-case
精彩评论