s2Get date format not working for registration time

I’m having some issues with s2Get and the date format when I pull the registration time.

When I insert this shortcode:
[s2Get user_field="s2member_last_payment_time" date_format="M jS, Y" user_id="537" /]

The result is: May 13th, 2020

But, when I insert this shortcode:
[s2Get user_field="s2member_registration_time" date_format="M jS, Y" user_id="537" /]

The result is: 2018-07-04 02:23:56

Notice the only different is the user field I’m pulling. Any ideas why the date_format isn’t working?

Interesting… No, I don’t know why. Let me take a look…

I see…

s2member/src/includes/classes/sc-gets-in.inc.php

if(preg_match('/time$/i', $attr['user_field']) && $attr['date_format'])
	if(is_numeric($get) && strlen($get) === 10) // Timestamp?
		{
			if($attr['date_format'] === 'timestamp')
				$get = (string)$get; // No change.

			else if($attr['date_format'] === 'default')
				$get = date(get_option('date_format'), (integer)$get);

			else $get = date($attr['date_format'], (integer)$get);
		}

It’s checking that it’s a Unix timestamp:

if(is_numeric($get) && strlen($get) === 10) // Timestamp?

But the registration time is stored as a date-time string, so it doesn’t get formatted by s2Get.

I could add a line to convert the string to time there…

if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?

Of course, if a non-date value gets to that point, some wrong date will be shown, but nothing that isn’t a time field should have gotten to that place to begin with…

Would you try that and see if it works as expected this time, please?

Let me know how it goes. :slight_smile:

Worked like a charm!

So, for the record, I went into the file s2member/src/includes/classes/sc-gets-in.inc.php and replaced line 82 with

if((is_numeric($get) && strlen($get) === 10) || ($get = strtotime($get))) // Timestamp?
1 Like

Right, that’s what I meant.

Great! Glad it worked. I think I’ll add it in the next release.

:slight_smile: