This topic is locked
[SOLVED]

wrong date format

3/28/2024 8:29:52 AM
PHPRunner General questions
I
I author

Hello everyone, with a Code snippet I retrieve information from a table with these fields: name+date. The date has the wrong format Y/m/d and this should be: d-m-Y I am trying to change the code below, but I am unable to do so. Please help, thanks.

$data = array();
$rs = DB::Select("absences", $data );
while( $record = $rs->fetchAssoc() )
{
echo ($record["dat"]);
echo(' - ');
echo ($record["nom"]),'

';
}
dageciDevClub member 3/28/2024

Maybe this could help:

echo (date('d-m-Y', strtotime($record["dat"])));

It takes a date string in the format 'Y/m/d', converts it to a Unix timestamp using strtotime(), and then formats that timestamp into the 'd-m-Y' format using date().

You are getting this format of date from your database. This is good thing because it doesn't depend of the users regional settings.

You can also try the tips from this PHPRunner article with built in functions:
https://xlinesoft.com/phprunner/docs/data_formatting.htm

I
I author 3/28/2024

Works great ! Thanks