AMPscript StringToDate (Next)
Turn a date string into a date value with AMPscript StringToDate in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including how it differs from Engagement.
Syntax
StringToDate(dateString) → date
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
dateString |
string | date | Yes | A date or timestamp string, or an existing date value |
Example
%%=StringToDate("2026-03-04T09:05:07")=%%
Renders 3/4/2026 9:05:07 AM.
The result is a date, so it can be formatted directly:
%%=FormatDate(StringToDate("2026-03-04T09:05:07"), "yyyy-MM-dd")=%%
Renders 2026-03-04.
Return value
date — printed on its own as a US short date with a 12-hour clock and AM/PM: 3/4/2026 12:00:00 AM for a date without a time. Length() over that value returns 20.
DatePart, FormatDate, DateAdd and DateDiff all accept the result. A DateAdd over it prints in ISO form (2026-03-05T00:00:00).
Behaviour
Same result as DateParse. A DateDiff in hours between StringToDate and DateParse over 2026-03-04 09:05:07 is 0.
| Call | Renders |
|---|---|
StringToDate("2026-03-04") |
3/4/2026 12:00:00 AM |
StringToDate("2026-03-04 09:05:07") |
3/4/2026 9:05:07 AM |
StringToDate("2026-03-04T09:05:07") |
3/4/2026 9:05:07 AM |
StringToDate("3/4/2026 9:05 AM") |
3/4/2026 9:05:00 AM |
StringToDate("4 March 2026") |
3/4/2026 12:00:00 AM |
StringToDate("March 4, 2026") |
3/4/2026 12:00:00 AM |
StringToDate("2026-03-04T09:05:07Z") |
3/4/2026 9:05:07 AM |
StringToDate("2026-03-04T09:05:07+02:00") |
3/4/2026 7:05:07 AM |
StringToDate("Wed, 04 Mar 2026 09:05:07 GMT") |
3/4/2026 9:05:07 AM |
A time without a date parses. Format(StringToDate("1:41 PM"), "HH:mm:ss") renders 13:41:00.
A day-first date is read month-first. StringToDate("5/8/2026") gives 5/8/2026 12:00:00 AM, the 8th of May.
A date value can be passed in. DateDiff(StringToDate(Now()), Now(), "MI") is 0.
Unreadable input is printed back. StringToDate("not a date at all") renders not a date at all instead of failing, so check the input before relying on the result.
Exactly one argument. An email with StringToDate(), with a second flag argument like the one DateParse takes, or with an encoding argument such as "UTF-8" cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
Show Next test script
<!-- Marketing Cloud Next test script for StringToDate. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[2026-03-04] got=[%%=Format(StringToDate("2026-03-04"),"yyyy-MM-dd")=%%]</p>
<p>c2 expect=[3/4/2026 12:00:00 AM] got=[%%=StringToDate("2026-03-04")=%%]</p>
<p>c3 expect=[3/4/2026 9:05:07 AM|3/4/2026 9:05:07 AM|3/4/2026 9:05:00 AM|3/4/2026 12:00:00 AM|3/4/2026 12:00:00 AM] got=[%%=StringToDate("2026-03-04 09:05:07")=%%|%%=StringToDate("2026-03-04T09:05:07")=%%|%%=StringToDate("3/4/2026 9:05 AM")=%%|%%=StringToDate("4 March 2026")=%%|%%=StringToDate("March 4, 2026")=%%]</p>
<p>c4 expect=[3/4/2026 7:05:07 AM|3/4/2026 9:05:07 AM|3/4/2026 9:05:07 AM] got=[%%=StringToDate("2026-03-04T09:05:07+02:00")=%%|%%=StringToDate("2026-03-04T09:05:07Z")=%%|%%=StringToDate("Wed, 04 Mar 2026 09:05:07 GMT")=%%]</p>
<p>c5 expect=[0|20] got=[%%=DateDiff(StringToDate("2026-03-04 09:05:07"),DateParse("2026-03-04 09:05:07"),"H")=%%|%%=Length(StringToDate("2026-03-04"))=%%]</p>
<p>c6 expect=[5/8/2026 12:00:00 AM] got=[%%=StringToDate("5/8/2026")=%%]</p>
<p>c7 expect=[2026|5|2026-03-04|2026-03-05T00:00:00|2] got=[%%=DatePart(StringToDate("2026-03-04T09:05:07"),"Y")=%%|%%=DatePart(StringToDate("2026-03-04T09:05:07"),"MI")=%%|%%=FormatDate(StringToDate("2026-03-04T09:05:07"),"yyyy-MM-dd")=%%|%%=DateAdd(StringToDate("2026-03-04"),1,"D")=%%|%%=DateDiff(StringToDate("2026-03-04"),StringToDate("2026-03-06"),"D")=%%]</p>
<p>c8 expect=[0] got=[%%=DateDiff(StringToDate(Now()),Now(),"MI")=%%]</p>
<p>c9 expect=[13:41:00] got=[%%=Format(StringToDate("1:41 PM"),"HH:mm:ss")=%%]</p>
<p>c10 expect=[not a date at all] got=[%%=StringToDate("not a date at all")=%%]</p>
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the save is rejected (HTTP 400) -->
%%=StringToDate()=%%
<!-- email 2: expect that the save is rejected (HTTP 400) -->
%%=StringToDate("2026-03-04 09:05:07",1)=%%
<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=StringToDate("2026-03-04 09:05:07","UTF-8")=%%
Differs from official docs
- Unreadable text is passed through. The reference does not say what happens to text that is not a date. In Next,
StringToDate("not a date at all")returned that text unchanged, without failing. Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
Plain, ISO and spelled-out dates render the same. Offset, Zulu and GMT timestamps land six hours apart: 2026-03-04T09:05:07Z gives 3:05:07 AM in Engagement and 9:05:07 AM in Next. An unreadable string aborts the Engagement page, while Next prints it back unchanged. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
- DateParse — the same parsing, with an optional second argument
- FormatDate — the usual next call
- DateAdd
- DateDiff
- Official reference