Home > InDesign Scripts > Display day/month name instead of number

Display day/month name instead of number

Sometimes we want to have full day/month name instead of just numbers. Here is really short little snippet to achieve this result. This post also can be found on Adobe’s InDesign scripting forum.

Easiest way is to create prototype for Date. We will first create Arrays of day/month names, and after that we will just return matching name. So, here are the functions:

Day:

Date.prototype.dayName = function() {
    var myDay = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    return myDay[this.getDay()];
}

Month:

Date.prototype.monthName = function() {
    var myMonth = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    return myMonth[this.getMonth()];
}

Now, how to use this? It’s really simple.

Get current day name:

var myDayName = myToday.dayName();

Or month name:

var myMonthName = myToday.monthName();

Or we can combine it in one long date format like this:

var myCurrentDate = myToday.dayName() + ', ' + myToday.getDate() + ' ' + myToday.monthName() + ', ' + myToday.getFullYear();

That’s it :D Simple and effective.

Have fun! ;)

About these ads
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 34 other followers

%d bloggers like this: