script for date and date/time fields

Albert Chan
Mega Expert

Hello,

I'm having an issue creating a script to set a date field based on a date/time field. This is the part script that I'm trying to use:

function createChange(){

  var change = new GlideRecord('change_request');

  change.initialize();

  change.setValue("requested_by_date", current.u_need_by_date);

The Requested By Date is a date / time field and the Need By Date is a date field. When I use this, the Requested By Date is not set correctly; it sets the date about a day early. I assume the issue is because the field types are different and that someone else has already figured this out.

Any help would be appreciated. Thanks in advance!

Albert

6 REPLIES 6

venkatiyer1
Giga Guru

Hi Albert,



I would do




var gdt= new GlideDateTime(current.u_need_by_date); // you can keep this line before var change =   new GlideRecord("change_request")


change.setValue("requested_by_date", gdt.getDate()); // get date will get system local date and getLocalDate will get user location date


Hi Venkat,



Thanks for the response, but it did not have the desired effect. Perhaps I was not clear. We have a customization where a Demand can spawn a Change Request. If I set the Need By Date on the Demand form as 2016-05-07, when I run my business rule, the resulting Change Request has a Requested By Date of 2016-05-06 20:00:00 and I'm just not sure why the dates don't match up.



Hopefully that makes things more clear. Thanks.


Albert


Hi Albert,



Could you share your code? It might be formatting getting in the way.




Cheers



Greg


venkatiyer1
Giga Guru

Hi Albert,



Yes, i got it the other way round. As greg mentioned, can you please share the code? Also, check the logged in users timezone setting or other personalized settings.