Changing how the date formatting appears

4 posts by 2 authors in: Forums > CMS Builder
Last Post: May 11, 2015   (RSS)

By gkornbluth - May 11, 2015

Hi Drewh,

If by "front end" you mean you mean your viewer (web page) here's a list of date format modifiers that you can use from a recipe in my CMSB Cookbook http://www.thecmsbcookbook.com.

SHOW DATES ON YOUR PAGE                                                                                                  
                            
Sometimes you’ll want to show the current year on your page, like when showing copyright information.
It’s easy to show the current year by adding 

<?php echo date("Y") ?> 

 to your page.

You can use any of the date modifiers to show date information as well, so:

<?php echo date("D, M jS, Y") ?>

Would show the Day of the week, and the Month, Day and Year.

You can format a date string to display as Day Date, Month Year on a detail page by using:

 <?php echo date("D jS, M  Y ", strtotime($your_tableRecord['your_date_ field'])) ?>

 Or, on a list page:

 <?php echo date("D jS, M  Y ", strtotime($record['your_date_field'])) ?>

 
If you thought, as I did, that you couldn’t format the displaying of the special fields createdDate and updatedDate,
you’d be wrong.

You can format these the same as any other date field.  

NOTE: The commas in the string determine where commas show in your display.

This is the complete list of Date formatting modifiers

A = Uppercase 12hr time syntax - Example: AM, PM
a = Lowercase 12hr time syntax - Example: am, pm
B = Swatch Internet time - Example: 000 through 999
c = ISO 8601 date (added in PHP 5) - Example: 2004-02-12T15:19:21+00:00
D = short textual representation of the Day - Example: Fri
d = Day of the month, 2 digits with leading zeros - Example: 03
e = Timezone identifier (added in PHP 5.1.0) - Example: UTC, GMT, Atlantic/Azores
F = Full Textual representation of the month - Example: January
G = Hours in 24 hour format without leading zeros - Example: 17
g = Hours in 12 hour format without leading zeros - Example: 7
H = Hours in 24 hour format with leading zeros - Example: 17
h = Hours in 12 hour format with leading zeros - Example: 07
I (capital i) = Whether or not the date is in daylight saving time - Example: 1 if Daylight Saving Time, 0 otherwise
i = Minutes with leading zeros - Example: 00 through 59
j = Day of the month without leading zeros - Example: 10, 25
L = Whether it's a leap year - Example: 1 if it is a leap year, 0 otherwise
l (lowercase 'L') =  full textual representation of the day of the week e.g. Monday, Tuesday
M = A short textual representation of a month, three letters - Example: Jan, Feb
m = Numeric representation of a month, with leading zeros - Example: 01
N = ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) - Example: 1 (for Monday) through 7 (for
Sunday)
n = Numeric representation of a month, without leading zeros - Example: 1 through 12
O = Difference to Greenwich time (GMT) in hours - Example: +0400
o = ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous
or next year, that year is used instead. (added in PHP 5.1.0) e.g. 2010
P = Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) - Example: +02:00
r = RFC 2822 formatted date - Example: Thu, 21 Dec 2000 16:01:07 +0200
S = English ordinal suffix for the day of month - Example: st, nd, rd, or th.
s = Seconds with leading zeros - Example: 28
T = Timezone abbreviation - Example: GMT, PST, EST, etc
t = Number of days in the given month - Example: 28, 31, etc.
U = Seconds since the UNIX epoch (January 1 1970 00:00:00 GMT) - Example: 1041604168
u = Microseconds (added in PHP 5.2.2) - Example: 654321
W = ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) - Example: 42 (the 42nd week in the
year)
w = numeric representation of the day - Example: 0 (for Sunday) through 6 (for Saturday)
Y = 4 digit year - Example: 2003
y = 2 digit year - Example: 03
Z = Timezone offset in seconds. The offset for time zones west of UTC is always negative, and for those east of UTC is
always positive. - Example: 43200 through 50400 
z = Day of the year (starting from 0) - Example: 0 through 365
 
And here are some Date String examples and their output

date("F j, Y, g:i a"); - March 10, 2010, 5:16 pm
date("m.d.y"); - 03.10.10
date("j, n, Y") - 10, 3, 2010
date("D M j G:i:s T Y"); - Sat Mar 10 15:16:08 PST 2010
date("D M jS, Y"); - Sat Mar 10th, 2010
date("H:i:s"); - 17:16:17
date('\i\t \i\s \t\h\e jS \d\a\y.'); - It is the 10th day.
 

You can learn more about date formatting at:

      http://www.php.net/date
                            

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By drewh01 - May 11, 2015

wow, perfect!

By gkornbluth - May 11, 2015

Glad I could help.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php