This topic is locked
[SOLVED]

 Datetime errors using View As Custom

5/20/2019 4:40:37 PM
PHPRunner General questions
R
rmac author

Wondering if anyone else has seen this:
I wanted to shorten my datetime displays by using

$value = date("m-d-Y <\b\\r> H:i");

in View As Custom. It worked as expected, except everytime the page would refresh, all of the values would update to the current date and time. I though it was a problem using now() as a default (and may still be somehow related) but it seems like it's even doing it with the now() default removed. Interestingly, it also seems to be all in the browser (tried both Chrome and Edge); if I check the underlying tables the values do not change, and if I change the View As back to regular datetime, the original values reappear.
So in short, all seems to work as expected until I choose Custom in the View As, no matter what the code. Any thoughts will be appreciated. Thanks.
Screenshot link

W
WilliamBDevClub member 5/21/2019

Here are a couple ways. Not tested as I am not at home.



$value = date("m-d-Y <\b\\r> H:i",strtotime($value));


or



$value = date_format($value,"m-d-Y <\b\\r> H:i");
admin 5/21/2019

PHP's date() function expects second parameter to be a timestamp. If none given it will just use the current datetime:

https://www.php.net/manual/en/function.date.php
Here is what your code is should be:

$value = date("m-d-Y <\b\\r> H:i", strtotime($value));
R
rmac author 5/22/2019

Once again, operator error. Of course, converting it into a string did the trick.

Thanks to both BillyB and Admin for setting me straight.