Date display format

4 posts by 4 authors in: Forums > CMS Builder
Last Post: April 8, 2010   (RSS)

Re: [squeazel] Date display format

By Dave - July 5, 2008

squeazel, welcome to the CMS Builder forum! :)

The code generator should automatically create a line of code that does this for you like the following:
Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/>

The missing step is the strtotime(), just add the code in red:
<?php echo date("t F Y", strtotime($record['date'])); ?>

Here's how that works (it's not required to know this but just in case you're curious).
- MySQL stores dates like this: 2008-06-21 20:11:17
- The strtotime() converts it to a 'unix timestamp' like this 1214104277 which is the number of seconds since 1970
- The date() function lets you specify a date format but requires the date as a unix timestamp so it knows exactly which date you mean.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Date display format

By ikanizaj - April 8, 2010

To addon a question:

What's the code to display this date 8th. Apr 2010. 5:30pm in this format 8.4.2010. 17:30

thanks for the answer?
--
Igor Kani¾aj

Re: [ikanizaj] Date display format

By Djulia - April 8, 2010 - edited: April 8, 2010

Hi [font "Verdana"]Igor,

Test : <?php echo date("j.n.Y. H:i", strtotime($record['createdDate'])); ?>

http://www.php.net/manual/en/function.date.php[/#336699]

Djulia