Jump to content

Recommended Posts

Posted

I came across a weird issue with date output and I would appreciate if you could thought-shower with me so I can find the root of the problem.

So I have a function that returns the content of a datetime-field. I use this function on two different templates, and used to include it on each of these templates seperately. But then in the process of tidying up the code I put that function on a separate php file in order to just include it on the mentioned templates, so I don't have to apply changes twice in the future, you know the drill.

Long story short, when in the code it says:

<?=strftime('%A, %e. %B %Y', $item->date_start)?> // cause it's german :D

it returns the correct date on one template but on the other I get a:

PHP Notice: A non well formed numeric value encountered in… and of course the good old 1. January 1970

with the exact same code!
When I change it to 

<?=strftime('%A, %e. %B %Y', strtotime($item->date_start))?>

It fixes the issue for that template but then it shows up on the other… So strange!

I might add that the way these two templates include the script differ a bit. 

include_once ('_organizer.php'); 

and

include_once ('site/templates/_organizer.php'); // this template is in the root folder because it is loaded via ajax

Any ideas?

 

Posted
On 11/9/2020 at 1:15 PM, LostKobrakai said:

Try the following, which will ensure you get an timestamp and not a formatted date string.


$item->getUnformatted('date_start');

 

thanks, I just saw this now and I'm sure it works cause I found the issue.

OK just so to clarify…

A is this one: include_once ('_organizer.php'); 
B
is this one: include_once ('site/templates/_organizer.php'); 

The field itself is set to output Y-m-d which doesn't work with strtotime($item->date_start).

A doesn't work, but because B is loaded over ajax and/or because it makes a detour over the root folder, it ignores that output format, outputs the unix timestamp instead and works fine.

If I remove the strtotime, A works fine cause the value is formatted anyway but it conflicts with the strftime of B. Very confusing. So when I removed the output format for the field altogether it works. 

All good now, thanks for the input.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...