Date display format

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

By squeazel - July 5, 2008

I'm having difficulty getting entry dates to display properly.

As a test, I have the following in my code:

<?php echo date("t F Y", $record['date']); ?><?php echo $record['date'] ?>

Sample output from the above looks like this:

31 January 19702008-06-28 00:00:00

So, on the right, the correct date is being pulled in, however somehow I am not translating it properly, and the date via the date function is generic, rather that what's in the CMS.

Any thoughts?

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