1

I am trying to format a date.

2015-12-01T00:00:00.000Z Into 12/01/2015 12:00AM

Now I have the following code to remove the Z and T and pass in a format that would work, but it looks like it is changing the minutes into hours, because it always put the minutes down as 12, when there is a 0 in the number.

2015-12-01T11:09:00.000Z converts to 12/01/2015 11:12AM

Here is the code:

%%[
IF @key == "send_date" OR @key == "activity_date" THEN

    SET @time1 = Row(@fourthActivtiesRowSet, 3)
    SET @time2 = Row(@fourthActivtiesRowSet, 4)
    SET @value = CONCAT(@value, ":",Field(@time1, 1), ":", Field(@time2, 1))
    SET @separateDate = BuildRowsetFromString(@value,"T")
    SET @rowDate = Row(@separateDate, 1)
    SET @date = Field(@rowDate, 1)
    SET @rowTime = Row(@separateDate, 2)
    SET @time = Field(@rowTime, 1)
    SET @dateTime = CONCAT(@date, " ", @time)
    SET @separateDate = BuildRowsetFromString(@dateTime,"Z")
    SET @rowDate = Row(@separateDate, 1)
    SET @dateTime = Field(@rowDate, 1)
]%%
    <td>
        %%=Format(StringToDate(v(@dateTime)), "MM/dd/yyyy HH:MMtt")=%%<br>
        %%=v(@value)=%%
    </td>
%%[ endif ]%%

Please advise on how to get the minutes to use 60 and the hours to use 12, right now it looks like the minutes is formatting to 12. Also, please upvote this, I am not up to 15 reputation yet to vote people up.

1 Answer 1

1

No need to convert the input string to a date first, but you will need to handle the timezone offset, since it's GMT (Z=> Zulu time).

%%[

 var @date, @formattedDate, @date2
 set @date = "2015-12-01T11:09:00.000Z"
 set @date2 = "2015-12-01T10:07:00.000Z"

 set @formattedDate = Format(dateadd(@date,"6","h"), "MM/dd/yyyy hh:mmtt")
 set @formattedDate2 = Format(dateadd(@date2,"6","h"), "MM/dd/yyyy hh:mmtt")

]%%
@date: %%=v(@date)=%%
<br>@date2: %%=v(@date2)=%%
<br>@formattedDate: %%=v(@formattedDate)=%%
<br>@formattedDate2: %%=v(@formattedDate2)=%%

Output

@date: 2015-12-01T11:09:00.000Z 
@date2: 2015-12-01T10:07:00.000Z 
@formattedDate: 12/01/2015 11:09AM 
@formattedDate2: 12/01/2015 10:07AM 

Reference: AMPScript Date and Time Formatting

Update: Added @date2 and @formattedDate2

3
  • That still did not solve the minutes being seen as 12 base and not 60 base. It comes across a 0 and pushes it to a 12. 12/01/2015 04:12AM is what comes out of 2015-12-01T10:07:00.000Z Format(StringToDate(v(@dateTime)), "MM/dd/yyyy HH:MMtt")=%%<br>%%=v(@dateTime) Commented Dec 29, 2015 at 16:36
  • I've updated my example. Your string format is incorrect. Give my example a try -- the whole format() line Commented Dec 29, 2015 at 17:04
  • Yep, that fixed it. Thanks for the help. I checked it off. Thanks. Commented Dec 29, 2015 at 18:36

You must log in to answer this question.

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