Wednesday, October 6, 2010

set the time in the time picker in MS CRM Date time field

Hi all,

some times we need the exact time , while some body is picking the date from the date picker. and the attribute is of date and time and showing full date and time also.
So once the user selects the date the time goes to 12:00 AM.
if (s)he wats to get the current time then just follow the followings

#1 get the selected date values by user

var selectedDate = crmForm.all.<datefieldname>.DataValue;
var date = selectedDate.getDate();
var month = selectedDate.getMonth();
var year = selectedDate.getYear();

#2 create the client date and fetch the time values

var clientDate = new Date();
var hr = clientDate .getHours();
var mnt = clientDate .getMinutes();
var sec = clientDate .getSeconds();

//change the value to hr and min
if(mnt >= 0 && mnt <=30){
hr = hr; // no change
mnt = 30; //make the mnt to 30
}
if(mnt > 30 && mnt <=59){
hr = hr+1; // add 1 to hr to round up
mnt = 0; // reset the mnt
}


#3 now create a new date with the year,month,date from the selected date and the hour,minutes,seconds from the client time

var finalDate = new Date(year,month,date,hr,mnt,sec);
//alert(finalDate);

#4 finally assing the time to the destination


crmForm.all.<datefieldname>.DataValue = finalDate;

Sudhanshu

No comments:

Post a Comment