how to set Days,Hours,Minutes,Seconds of a Date/Time field

Shir Sharvit
Tera Contributor

Hi,

I have the field u_date of type Date/Time.

How can I add days to this field and set the hours,minutes, and second to what I want.
For example:

u_date = 12/05/2024 15:00:00

add 2 days, set hours, minutes and seconds to: 16:30:22

u_date =  14/05/2024 16:30:22

 

thank, Shir

5 REPLIES 5

Krushna R Birla
Kilo Sage

Hi @Shir Sharvit 

 

You can use below code to achieve this,

 

var u_date = new GlideDateTime('2024-12-05 15:00:00'); // Convert string to GlideDateTime object
u_date.addDaysUTC(2);  //Add 2 days to the date
u_date.addSeconds(5422); //16:30:22 from 15:00:00 is total 5422 second in total
gs.info(u_date.getValue()); // This will print the updated date/time value

 

KrushnaRBirla_0-1715510393279.png

 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

@Krushna R Birla 

 I just want to add the days. I want to set the minutes and seconds by myself without adding

Krushna R Birla
Kilo Sage

So, in that case you can use only u_date.addDaysUTC(2);  //Add 2 days to the date. This will add 2 days

 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Community Alums
Not applicable

Hi @Shir Sharvit ,

Wanted to know more on the requirement, can you please tell me how are you going to take input, like how many days to add?

Do you have a field to store this or any script which invoked a popup to take input for number of days??

 

Thanks & Regards,

Sanjay Kumar