php - Date format should be in cst -


i have date in our database "2014-03-06 16:23:33". wanted display "mar 06, 2014 04:23:33 pm cst". using cakephp.

eg:

$this -> html -> cdate ($courselog['courselog']['completed_time'],'datetimes'); 

thanks in adv.

plz answer asap.

update
while stated wasn't sure if cakephp had specific helper this, i'm sure not.
own documentation mentions datetime class, , link php docs
, github search called cdate shows empty, cdata entirely different anyway...


as follow comment, i'll delete, completeness add here:

i don't know if cakephp has specific helper this,

$date = new datetime($yourdatestring); $date->format(date_rfc820); 

should close. compose own format according need, or check the predefined constants readily available.

ok, date_rfc850 constant isn't exact match of format looking for, , string manipulations (as in series of substr , explode-implode calls) tedious , messy , amateurish. look @ format parameters!
suspect you're looking this:

$date = new datetime($courselog['courselog']['completed_time']); $asstring = $date->format('m d, y h:i:s e'); 

perhaps it's safer create datetime instance format know, , expect. know how string formatted, can use static method datetime::createfromformat, too:

$date = datetime::createfromformat(     'y-m-d h:i:s', //yyyy-mm-dd hh:mm:ss format     $courselog['courselog']['completed_time']//the string parse ); $asstring = $date->format('m d, y h:i:s e'); echo $asstring, php_eol; 

as can see from codepad, works perfectly...

the format explained:

  • m: short textual representation of month, f gives full month
  • d: 2 digit (with leading zeroes) representation of day, change j drop leading zeroes
  • y: 4 digit year, opposed y, gives 2 digits
  • h: 12 hour leading zeroes, g drops leading zeroes. capitalize either format , 24 hour version
  • i: minutes, leading zeroes
  • s: seconds, leading zeroes
  • a: or pm, change a am or pm
  • e: time-zone identifier, alternatives t (timezone abbreviation) or o , p (both difference gmt in hours, p adds colon between hours , minutes (+0400 vs +04:00)

bottom line, php comes datetime object offers solid way work dates , times, i'd suggest use core object. whatever cakephp offers, it'll wrapper around the datetime , related classes


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -