1

I get data from a database in YYYY-mm-dd format, but I want to show just dd.mm (example - I get 2010-05-28; I want to show 28.05)

Could you help me?

Thanks

4
  • possible duplicate of Change date format (in DB or output) to dd/mm/yyyy - PHP MySQL or zillion others Commented May 22, 2010 at 15:23
  • 1
    The duplicate points to mySQL's DATE_FORMAT() which is much better suitable for this. Commented May 22, 2010 at 15:26
  • Someone is desperately need to learn how to use search... Commented May 22, 2010 at 15:26
  • and why the up vote, anuseful question :D :D :D Commented May 22, 2010 at 21:18

4 Answers 4

4

The fast way is to convert to timestamp and back out to a date. This isn't safe for dates outside the normal epoch though:

$dateString = date('d.m', strtotime($dateFromDb)); 
Sign up to request clarification or add additional context in comments.

Comments

3

You can use the date_format function to format the data as it comes out of the database. For example:

mysql> select tf, date_format(tf, '%d.%m') from times; +---------------------+--------------------------+ | tf | date_format(tf, '%d.%m') | +---------------------+--------------------------+ | 2010-11-02 00:00:00 | 02.11 | +---------------------+--------------------------+ 

Comments

1

To interchange date formats I use strtotime() in conjunction with date(), like this:

// Assuming the date that you receive from your database as // YYYY-mm-dd is stored in $row['date'] $newformat = date('d.m', strtotime($row['date']); 

Comments

0

To convert the date format from yyyy-mm-dd to dd.mm in php,

<?php $dt='2010-05-28'; $dt=date('d.m',strtotime($dt)); echo $dt; ?> 

The o/p will be, 28.05

1 Comment

That's what I said almost 2 years before you posted this. You can just upvote my answer or something.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.