I am using the following %%=FormatDate(dateadd(now(1), 0, "H"), "DD MMMM YYYY hh:ss tt",,"")=%%
in a email and cloud page, what i dont get is that each time i change the preview subscriber the time changes, same applies for the cloud page, i am trying to capture the time of submission in a data extension and found while testing 3 submissions 5-10 seconds apart had times that were 10:42 PM, 10:11 PM, 10:20 PM. Is there something wrong i have done with the code?
2 Answers
A couple of issues... You're formatting the current time incorrectly as you're providing the seconds datepart where the minutes datepart should be - hence the reason for the time changing every second. I think you're looking for this format string to render on your page:
%%=FormatDate(now(1), "MMM DD, YYYY", "HH:MM tt", "en-US")=%%
With respect to the Now(1), this attempts to get the date and time a job (email) was deployed. In Send Preview and on a Landing Page with no context, there is no job, so the function returns the current time. If you're not interested in the Job deployment time and actually want the system time, use Now().
Lastly, could you explain where your reference to a data extension comes in?
-
Thanks very much, was right in front of me and couldn't see that I had used SS rather than MM in the code. I have updated my code to Now() also as only need it in my cloud page (Smart capture, hidden field)– AndywCommented May 13, 2020 at 20:22
In the FormatDate you have added as "DD MMMM YYYY hh:ss tt".
I think you are expecting minutes to be populate but since you have added it as seconds in format date on every submit the time is getting changed.
Just change the second to minutes like below
%%=FormatDate(now(1), "MMM DD, YYYY", "HH:MM tt", "en-US")=%%
Let me know if this helps.
-
Sorry @Naveen VM, I accidentally edited your code portion as the answer looked so similar to my own.– MaccaCommented May 13, 2020 at 5:48
-
No Problem @Macca. Its nice to see we are crossing each other on answering :) Commented May 13, 2020 at 9:12