adding 1 year to a date field is showing wrong value.

vass2
Mega Expert

Hi All,

Here i am trying to add 1 year and fetch result into u_next_verification_date. when i execute in the message it shows correct , but in the field value showing wrong. 

Any help is highly appreciated.

Vass

find_real_file.png

When i update the record it is showing the correct  date values in the message below.

find_real_file.png

But when i open the record and check the field value it showing wrong. (Highlighted field).

Also i wish the date value should be the blue rounded one hours/minutes/seconds. 

find_real_file.png

 

1 ACCEPTED SOLUTION

Try Below Code,Its working fine

 

var gr = new GlideDateTime();
var gr1=gs.yearsAgo(-1);
var date= gr1.split(' ')[0];
var time=gr1.split(' ')[1];
var gd = new GlideDate();
gd.setValue(date);
date=gd.getByFormat('dd/MM/yyyy');
gr1=date+' '+time; //gr1 is your converted format
gs.addInfoMessage(gr1);

current.u_next_verification_date =gr1;

current.update();

View solution in original post

40 REPLIES 40

Hi Ravi,

 

Thanks for the reply. 

after changing var gr = new GlideDateTime(); to var gr1 = new GlideDateTime();

Showing time also correct.

Thanks all for your help

 

Regards,
Srinivas

oops.. But why it is showing 1 hour less ?

find_real_file.png

Oh I've missed to give nvd in glide..!! Inserting the below at line9 is the shortest way I believe. var dt =new GlideDateTime(nvd).getDate().getByFormat("MM-dd-yyyy"); //Change as required var ti = new GlideDateTime(nvd).getTime(); gs.info(dt+'---'+ti); current.u_next_verification_date = dt+' '+ti;

And, you cannot mark 2 answers as correct and so, mark the one that most helped you as correct and the other answer/s can be marked as helpful if you felt so.

Hi Archana,

I made the change but time is still showing 00:00:00

Thanks for giving another way doing it, and let me know how to get the time also.

 

Regards,
VASS