Jump to content

Need help trying to format a date


Sean

Recommended Posts

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...