0

Good afternoon people!

I have a problem and after a lot of research I still don't know how to solve it

I have two variables @travel_time and @trip_duration, where I need to add the hours and minutes of the second to the first and create a new variable called @arrival_time

I didn't see any way to do this operation in ampscript

Does anyone know of a way I can help myself? I've been stuck on this task for 3 days

Example:

%%[
set @data1 = @travel_time 
set @data2 = @arrival_time 
]%%
%%=v(@data1)=%% %%=v(@ data2)=%% 

______________________________________ 
21:00:00.000Z     08:00:00.000Z 
______________________    
04:00:00.000Z     02:55:00.000Z
3
  • So basically you are looking to take the time of departure (@travel_time) and then take the duration (@trip_duration) and add that time onto the departure to get 'estimated arrival' time (@arrival_time)? If so, could you provide a sample of the data in these fields so we can see format and data types? Commented Jan 25, 2023 at 15:50
  • set @data1 = @travel_time set @data2 = @arrival_time %%=v(@data1)=%% %%=v(@ data2)=%% ______________________________________ 21:00:00.000Z 08:00:00.000Z ______________________ 04:00:00.000Z 02:55:00.000Z Commented Jan 25, 2023 at 17:35
  • Is it just the time or is it date time format? E.g. HH:MM:SS.mmmZ (10:41:12.932Z) or YYYY-MM-DDTHH:MM:SS.mmmZ (2023-01-25T01:22:32.234Z)? This will change the way the date math is handled. Commented Jan 25, 2023 at 21:05

1 Answer 1

0

That should look something like this:

set @hour_offset = DatePart(@trip_duration, "H");
set @minute_offset = DatePart(@trip_duration, "MI");
set @travel_time = DateAdd(@trip_duration, @hour_offset, "H");
set @travel_time = DateAdd(@travel_time, @minute_offset, "MI");

We extract the hours and minutes, then add them consecutively to form the new value. Note that DateAdd returns a new, independent date, so we have to use @travel_time in the second calculation.

2
  • thanks for the answer but the sum is not correct, some examples that are returning: '04:00:00.000Z 02:55:00.000Z 01/25/2023 05:50:00' '15:04:00.000Z 03:51:00.000Z 01/25/2023 07:42:00' Commented Jan 25, 2023 at 17:38
  • @felipemartins Hmm, not sure what to say. Maybe you could just extract the values with DatePart, add the times together, then create a new date value?
    – sfdcfox
    Commented Jan 25, 2023 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .