0

I have a DE with a date column in this format

enter image description here

I desire to change this in the email to read 23 March and i am using FormatDate but it doesn't work

Below is my code

    set @Outagedate = field(@row,"Outage_dates")
    set @Outagedate = formatDate(@Outagedate, "m")

I have the values in a table. Below is my html.

<td style="text-align:center;">%%=v(@outagedate)=%%</td>

When i preview this, the email has blanks for the date column. (below)

enter image description here

3
  • Hope this might help... ampscript.guide/formatdate ......also I would first suggest to output and check your 'Outagedate' before formatting, just to check the value is pulled! Commented Mar 3, 2021 at 4:38
  • 1
    Also I am hoping you are using the LookupRows while pulling your rows [asking as I don't see the code above... if NOT here is an example how to use Lookuprows, Row and Field functions together .... ampscript.guide/lookuporderedrows Commented Mar 3, 2021 at 4:40
  • Yes I am using LookupRows and yes it outputs like for like from the DE before formatting. Yes I did read that article and used the monthday in the code above.
    – Rahul
    Commented Mar 3, 2021 at 19:53

1 Answer 1

1

DD/MM/YYYY is an ambiguous date format, which will need to be handled based on your business unit configuration.

Per https://ampscript.guide/dateparse

The function uses the date format defined in the respective the Business Unit. For example, MM/DD/YYYY when the Business Unit date format is set to English (United States) or DD/MM/YYYY when the Business Unit date format is set to English (United Kingdom). If you attempt to parse a string in an incorrect format based the Business Unit date format, for example 30/12/2020 when the Business Unit date format is set to English (United States), then the function will return a String was not recognized as a valid DateTime error.

For example in my business unit, if I parse a date in MM/DD/YYYY format, it works:

%%[

set @dateString= "03/23/2021"
set @year = datePart(@dateString, "Y")
set @month = datePart(@dateString, "M")
set @monthName = datePart(@dateString, "monthName")
set @day = datePart(@dateString, "D")
set @formatted = format(@dateString, "M")

]%%
<br>dateString: %%=v(@dateString)=%%
<br>year: %%=v(@year)=%%
<br>month: %%=v(@month)=%%
<br>monthName: %%=v(@monthName)=%%
<br>day: %%=v(@day)=%%
<br>formatted: %%=v(@formatted)=%%

Outputs this:

dateString: 03/23/2021
year: 2021
month: 03
monthName: March
day: 23
formatted: March 23

But when I use 23/03/2021, it doesn't:

https://i.imgur.com/9nIb3YO.png

6
  • My BU date format is set to English(Australia) so the ddmmyyyy i would think is the right format for this setting?
    – Rahul
    Commented Mar 3, 2021 at 20:27
  • Try using format() instead of formatDate() -- as in my example Commented Mar 3, 2021 at 20:32
  • my datestring is a lookup row = set @Outagedate = field(@row,"Outage_dates") The code works when i define the datestring as "03/23/2021" but not when the datestring is a lookup row
    – Rahul
    Commented Mar 3, 2021 at 20:51
  • What do you see when you simply output @outputDate without formatting at all? Commented Mar 3, 2021 at 21:56
  • I see the date like for like as it is shown in the DE.
    – Rahul
    Commented Mar 3, 2021 at 22:01

You must log in to answer this question.

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