PDA

View Full Version : Need help trying to format a date


Sean
May 23rd, 2012, 06:07 PM
Hello,

I am trying to figure out how to write a rule for formatting a date.

Date = 06/01/2012

and should return a value of "Friday, June 1".

Any help would be greatly appreciated.

Thank you,

Sean

dreimer
May 24th, 2012, 06:36 AM
I would like to see how to do this as well. It looks like the built in rules only allow for using the date as integers.

FreightTrain
May 24th, 2012, 08:23 AM
Sean,
The 'getDay()' function returns the day of the week as an integer, with 0 being Sunday and 6 being Saturday. To get the day of the week you need to use an array to equate the number for the day of the week with the actual day. Then you need to apply the date format function to the field providing the date value. In the example below I just used 'Today()', but this could be 'Field("Event Date")'


var theDate=new Date(Today());

var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var newDate = weekday[theDate.getDay()];

return newDate+", "+FormatDate(Today(), "lm, d");
Hope this helps.

ehazzard
May 24th, 2012, 08:52 AM
This can also be done with a simple text rule as well:



return FormatDate(Field("Date"), "ld, lm d");

This rule takes the variable "date" and formats using the Long Day(ld) comma Long Month(lm) and the day(d). All formatting in the quotes will be returned as literal text; this is a pre-built rule in the Building Blocks under the Functions tab > date.

FreightTrain
May 24th, 2012, 10:14 AM
Suuuurrrrreeee take the easy way.

Sean
June 4th, 2012, 02:20 PM
Sorry for not replying sooner. Thank you guys for your help. All i can say is that this forum is super helpful and full of great information.