Notifications
Announcements
No record found.
How do I get the month from a date/time field with javascript? What I need is to get the month from the field and put it as the record name, thank you.
*This post is locked for comments
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
I need the date from the field, not today's current date, eg: field says 02/31/2010, the name of the record will have February.
Hello.
Try to use following script:
if (crmForm.all.<date field>.DataValue == null)
return;
var monthnames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var name = monthnames[crmForm.all.<date field>.DataValue.getMonth()];
I need a simplified version of this script that gets the month, in number format, from a specific date field named in the function.
If you want this as a function try something like this;
// ** This code takes createdon date, passes to a function.
var anyDate = Xrm.Page.getAttribute("createdon").getValue();
var returnedMonth = ReturnMonth(anyDate);
alert(returnedMonth);
// ** A simple function to return month number
function ReturnMonth(aDate) {
aDate = new Date(aDate);
// 1 is added as months start at 0!
return aDate.getMonth() + 1;
}
Thank you, Neil!!!
function getDateMonth()
{
//get date
var date = Xrm.Page.getAttribute("new_date").getValue();
var d = new Date(date);
//show Month in alert window
Xrm.Utility.alertDialog("Month is : "+ (d.getMonth()+1));
Note : The index position of getMonth() method starts from 0. So to complete all the 12 months we need to add 1 into it. Otherwise for December month the output would have been 11 instead of 12.
Thanks,
Sam
Hi BeWood,
var date = Xrm.Page.getAttribute(yourDateField).getValue();
var objDate = new Date(date),
locale = "en-us",
month = objDate.toLocaleString(locale, { month: "long" });
Xrm.Page.getAttribute(YourRecordFieldName).setValue(month);
//alert(month);
Thank you,
If my solution is answered you Question mark it as "Answered".
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2