This topic is locked

How to change date format in this code ?

8/28/2021 7:30:01 PM
PHPRunner General questions
jvbsoftware author

I want to fill a variable with a text and also with a date that I retrieve from a field of a table. But the date is in wrong format,
I want this format : DD-MM-YYYY

$msg.= "this is the booking of : ".$values["lesdatum"]."\r\n";

What do I need to change in the code? thanks

DealerModules 8/29/2021

Hi jvbsoftware,

Will this work?

$msg.= "this is the booking of : ".date("d-m-Y", $values["lesdatum"])."\r\n";


HJB 8/29/2021

... simpliest way to go is to change the "standard date format", if possible ...

img alt

jvbsoftware author 8/29/2021

Setting the date format is not enough.( like the screenshot from HJB )
To populate a variable from a table you need code. For example the code below:

$date = $values['orderdate'];
$newdate = date("d-m-y", strtotime($date));

thanks for your help

HJB 8/29/2021

Thanks for teaching lesson, yet at least me is thinking this:
If I would run a web application with dates inside, I would
set the standard date in conformity to the country of most
of the users, simply to avoid misinterpretation of date formats.

If suddenly, I may want to include a NEW date format (NB:
you mentioned your first code worked) into the arena, then
it would generally look strange, at least to me.

jvbsoftware author 8/29/2021

My intention is certainly to teach someone, my knowledge is below par.
But when I choose the locale (as you showed in the screenshot ) , it is not enough to write the correct date format in a variable, so I added code as I showed. thanks

HJB 8/29/2021

img alt

... got your point ...

admin 8/29/2021

@HJB is right, the easiest way is to handle date formats via regional settings, so you do not need code it manually every time. However it is not enough just to select the required date format via regional settings since it is a part of PHP code. PHPRunner offers an API function that will apply the 'View as' format in your code.

Check Data Formatting article in the manual.

jvbsoftware author 8/29/2021

Where can I find phprunner this setting as HJB shows in the picture ?

HJB 8/29/2021

WISHED OUTPUT: 29-08-2021

Posted picture PHP code was just to make clear that a wished "2021"
display as above requires a "Y", not a "y" which just means "21".

Anyway, I gambled a little bitat my end: My standard date format is
DD/MM/YYYY in junction with a DATE field named "date".

I had been putting the following code under PHPRunner section
"Fields", putting the following code after the selection of "View as"
within "custom code" in regard to my date field named "date" and
after new generation of code all my dates in LIST page and else are
correctly showing the date format DD-MM-YYYY (Output: 29-08-2021).

$value = date("d-m-Y",strtotime($value))

This is indeed my very "last word" on the issue.