setDateNumericValue() function of a GlideDateTime object

Not applicable

Hello,

In a business rule, I'm trying to set a date-time in milliseconds to a GlideDateTime object by the function setDateNumericValue().
Following is my code:

var myDate = new Packages.com.glide.glideobject.GlideDateTime();
myDate.setDateNumericValue(myDate_milliseconds);

But it seems doesn't work. After the function setDateNumericValue(), I check myDate value and it's the moment when myDate was initiated but not the corresponding value of myData_milliseconds.

Could someone show me if I did it wrong? Or please give me another solution for my objective.
Thank you for your help.

Regards,
Burin

2 REPLIES 2

mlemartien
Kilo Contributor

I think the method is setNumericValue(), not setDateNumericValue().


If you're inserting a new record, it's setNumericValue. If you're setting the value on an existing GlideRecord object with that field type, you'll want to use setDateNumericValue.


However, remember that these methods expect an input that is a number, and that is in MILLIseconds, not seconds. Keep this in mind, because other APIs like gs.dateDiff(startTime, endTime, true) will return a number in SECONDS. So you might need to do something like this:



var diffValue = gs.dateDiff(startTime, endTime, true);


gr.u_duration_field.setDateNumericValue(diffValue * 1000);