Problem Saving Today's Date to a Custom Registration Field

I have a client who needs to keep track of some bookkeeping data. This is not something s2Member does out-of-the-box. I’ve configured a Custom Registration Field and custom Pro-Form templates to save the date of the last purchase made on the site. I use the following code on the Pro-Form template:

<!-- Last Purchase Date -->
<div style="display: none;" id="s2member-pro-stripe-checkout-form-custom-reg-field-last-purchase-date-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-checkout-form-div s2member-pro-stripe-form-custom-reg-field-last-purchase-date-div s2member-pro-stripe-checkout-form-custom-reg-field-last-purchase-date-div">
<label for="s2member-pro-stripe-checkout-custom-reg-field-last-purchase-date" id="s2member-pro-stripe-checkout-form-custom-reg-field-last-purchase-date-label" class="s2member-pro-stripe-form-custom-reg-field-last-purchase-date-label s2member-pro-stripe-checkout-form-custom-reg-field-last-purchase-date-label">
<span>Last Purchase Date *</span></label><br />
<input type="text" maxlength="100" autocomplete="on" value="<?php echo date('d-m-Y');" ?> name="s2member_pro_stripe_checkout[custom_fields][last_purchase_date]" id="s2member-pro-stripe-checkout-custom-reg-field-last-purchase-date" autocomplete="on" aria-required="true" tabindex="109" data-expected="alphanumerics-spaces-punctuation-10-e" class="s2member-pro-stripe-custom-reg-field-last-purchase-date s2member-pro-stripe-checkout-custom-reg-field-last-purchase-date form-control" />;

This code assigns today’s date to the value parameter (value="<?php echo date('d-m-Y');"), hides the form field and autocompletes it. I’m using a data validation of exactly 10 alphanumeric/spaces/punctuation characters (data-expected="alphanumerics-spaces-punctuation-10-e"). This works for s2Member and WordPress. They recognize this information as a date and it is saved as a Unix timestamp within the database.

However, when s2Member exports the “date” it is exported as a string and we can’t get Excel to recognize it as a date. We’ve tried changing the column format, but Excel simply refuses to change the text value to a date. It is in d-m-Y (e.g, 22 Feb 2017) format and I have no idea why Excel won’t change it to a date, but it won’t.

So I went back to s2Member’s Custom Registration Field and tried to require the field to validate as a date. But when I do that, I get an error message that the Last Purchase Date must be a date. In other words, s2Member or PHP isn’t recognizing the string input as a date even though it recognizes it as a date once it has been saved…

Does anyone have any suggestions here? I’ve tried wrapping the date('d-m-Y'); in quotes. I’ve tried removing the double-quotes around the value (value= <?php echo date('d-m-Y'); but both result in exactly the same “Last Purchase Date must be a date” error message. I’m pulling my hair out here. :wink:

This appears to be an inherent problem in converting dates from PHP to Excel.

I think this might help: https://excelribbon.tips.net/T010849_Converting_UNIX_Date_Time_Stamps.html

If not, try Googling “convert php date to excel” for some other suggestions.

Thanks, Tim. That wasn’t the issue because the date was displaying as “22/02/2017” in Excel. (I’ve actually used that Unix timestamp to date formula in the past.) In any case, I reported an issue with the Simple Export from s2Member which showed up in yesterday’s s2Member release, and whatever Jason (@jaswsinc) did to fix it, also fixed the problem with my “Last Payment Date”. :slight_smile: