Jump to content

Help with date format - query from mysql


dbk

Recommended Posts

Hi

 

I can't seem to get the dateformat the way I want!

From mysql the dateformat is yyyy-mm-dd, but I would like to display it dd-mm-yyyy in my page! How do I do this?

 

And is it possible to display it like dd.mm.yyyy?

 

This is a part of the code:

 

$project_db = "SELECT * FROM $db_$db_tbl_project WHERE project_id = '" . $_SESSION['project_number'] . "' ";
$project_result = mysql_query($project_db)
      or die("Invalid query: " . mysql_error());
$project_row = mysql_fetch_array($project_result);

$project_start_date = $project_row['project_start_date'];

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/204885-help-with-date-format-query-from-mysql/
Share on other sites

I'm sure someone will show you how to format the date directly in MySQL, so here's how to do it in PHP...  use a combination of the strtotime and date functions:

<?php
$project_start_date = $project_row['project_start_date'];
echo date('d-m-Y',strtotime($project_start_date));
//
//  or
//
echo date('d.m.Y',strtotime($project_start_date));
?>

 

Or you can to it without strtotime and date

<?php
list($yr,$mon,$day) = explode('-',$project_start_date);
echo "$day-$mon-$yr";
//
// or
//
echo "$day.$mon.$yr";
?>

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.