Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Date issue

Avatar

Former Community Member

Ok, this should be very simple but I am stuck.

I want to get the Month, Day and Year for the current day.

Here's my script:

var

tDate = Date();

app.alert("tDate is: " + tDate );

// get today's month

var M = tDate.getMonth() + 1; // 0 based

app.alert("M is : "

+ M );

var D = tDate.getDate(); // get today's day

var Y = tDate.getFullYear(); // get today's year

I get the tDate, which is correct, but I can't get the month, day and year. Please help.

Thanks!

Student

1 Accepted Solution

Avatar

Correct answer by
Level 6

Try this way.

var tDate = new Date();
app.alert("tDate is: " + tDate );

try{
var M = tDate.getMonth()+1; // 0 based - // get today's month
var D = tDate.getDate(); // get today's day
var Y = tDate.getFullYear(); // get today's year
app.alert("M: "+ M +"D:" +D + "Y:"  +Y);
}
catch(e){app.alert(e)}

Raghu.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

Try this way.

var tDate = new Date();
app.alert("tDate is: " + tDate );

try{
var M = tDate.getMonth()+1; // 0 based - // get today's month
var D = tDate.getDate(); // get today's day
var Y = tDate.getFullYear(); // get today's year
app.alert("M: "+ M +"D:" +D + "Y:"  +Y);
}
catch(e){app.alert(e)}

Raghu.

Avatar

Former Community Member

Thanks Raghu

That was silly to miss "new" there