124
Views
14
Comments
Solved
Subtract hours and date
Question
Application Type
Reactive
Service Studio Version
11.54.39 (Build 63034)
Platform Version
11.25.0 (Build 41743)

Is there a way i can subtract the hours and day at the same time at a one code? i have this my code but the hours only subtracts i have this error in the date of having 1900.


2024-09-12 02-43-38
Deepsagar Dubey
Solution

Okay if you need yesterday date and one hour before than current time then you can use this expression 

AddHours(AddDays(CurrDateTime(), -1), -1) 

Output - 

2024-01-31 05-29-41
Akshay Deshpande
Solution

The date picker input is  SelectedDateTime(Date) and local variable is Dateset(datetime)
Adding addhours() function 14 (put this in site property if it will change in future) hours as you need to set for 2PM

2024-07-22 07-29-42
Ruwin Olga Winston George

Hi @budang haba ,

Are you setting the StartDate3 value the first time or is it set with a value beforehand?

Thanks.

UserImage.jpg
budang haba

it is date time input field

2024-09-12 02-43-38
Deepsagar Dubey

Hello @budang haba 

This expression will work and return time only, you can try it first by print somewhere in your screen or debug after assignment.

DateTimeToTime(AddDays(AddHours(CurrDateTime(), -1), -5))

But my question is that why you are subtracting days ?

AddHours(CurrDateTime(), -1) - it'll subtract 1 hour from current time. AddDays(AddHours(CurrDateTime(), -1), -5)  - It'll subtract 5 days from current date.
DateTimeToTime(AddDays(AddHours(CurrDateTime(), -1), -5)) - it'll return only time from date time.

So no use of AddDays(AddHours(CurrDateTime(), -1), -5)  expression.

Thanks
Deep

UserImage.jpg
budang haba

 i have to use subtracting the day and hours because i need a yesteday date function for the deadline function

2024-09-12 02-43-38
Deepsagar Dubey
Solution

Okay if you need yesterday date and one hour before than current time then you can use this expression 

AddHours(AddDays(CurrDateTime(), -1), -1) 

Output - 

UserImage.jpg
budang haba

Thanks man it actually worked but one thing that i forgot is there a way that i can lock my date picker in a specific time only ? like it will only be 2:00 PM?

2024-01-31 05-29-41
Akshay Deshpande

Hello budang haba,

If you convert date in hours and add only one thing, it will still work 
Example: 1 day = 24 hours, so accordingly, you are able to solve this in one stroke with the addhours function.


Thanks and Regards,
Akshay Deshpande

UserImage.jpg
budang haba

Thanks man it actually worked but one thing that i forgot is there a way that i can lock my date picker in a specific time only ? like it will only be 2:00 PM?

2024-01-31 05-29-41
Akshay Deshpande

Do one thing: from date picker, pick only date not date time and on selection of datapicker action, set the time whatever you want (in data time variable)

UserImage.jpg
budang haba

how can i manually set it? sorry im a beginner here

2024-01-31 05-29-41
Akshay Deshpande
Solution

The date picker input is  SelectedDateTime(Date) and local variable is Dateset(datetime)
Adding addhours() function 14 (put this in site property if it will change in future) hours as you need to set for 2PM

UserImage.jpg
budang haba

it works man but how about the day? i want it to have yesterday's date

2024-01-31 05-29-41
Akshay Deshpande

same 14-24 = i.e (-10) add -10 instead of 14 in  above experssion

UserImage.jpg
budang haba
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.