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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.