{today} vs {date_created}

I have a form that has an html field in it to display today’s date. We need to display this to the site user as they fill out the form. It is entered as:

<div>{today:format:m/d/Y}</div>

We also use Gravity PDF to create a PDF of each entry. In the PDF I use the entry date of that entry, entered in the template as:

$membership_date = strtotime(rgar( $entry, 'date_created' ));

echo date("m-d-Y", $membership_date); 

This has worked fine for us for months. However, we are troubleshooting another issue, and sent through test entries yesterday on 9/11/24, and the entry date reflects this when looking at the entries in the GF → Forms → Form → Entries. However, the system is generating the PDF and the $membership_date renders in the PDF as having a date of 9/12/24. This has only happened on the 3 tests entries created on 9/11/24, between 7-8pm Central Time/Chicago. Our site’s timezone is also set to Chicago/Central Time.

Is there anything wrong with using the above code in the manner that I’ve described here? Or, should I be using {date_created} instead of {today} in the form builder admin where I’ve set the html field to contain the {today} variable?

I looked through the doc pages for {today} and {date_created}, but I could not see anything that would imply it could be causing this issue.

Last, I sent through another test today and the date rendered just fine.

Hey @user648c88d38f0fe544,

The $entry['date_created'] is saved in UTC time and isn’t converted to your site’s local time. So anytime a form submission is made between 6pm and 11:59pm Chicago time the code you are using will display the date as tomorrow (Chicago currently being 5 hours behind UTC time).

Some options to fix this in the PDF are:

  1. Use echo esc_html( $form_data['date_created_usa'] ); to display the submission date in the format m/d/Y
  2. Swap the date() function for wp_date(), which will convert your UTC timestamp to your website’s local date
  3. Remove the PHP code and output the {date_created:format:m/d/Y} merge tag

All the best with your project.

1 Like