1

Right now i am the month, day, and year of a user seperated in three db fields titled month, day, year.

When i display it i am doing:

$month = $row['month'];
$day = $row['day'];
$year = $row['year'];

then to echo it:

$month/$day/$year  

The problem is that the PHP is doing mathematics here and dividing the numbers... What can i do to not make that happen and let it simply display the dates..

Thanks

AAA
  • 3,054
  • 10
  • 50
  • 71

4 Answers4

2
echo $month.'/'.$day.'/'.$year;
Andrew Jackman
  • 13,275
  • 7
  • 34
  • 44
2

try this out :

echo "{$month}/{$day}/{$year}";
Naftali
  • 142,114
  • 39
  • 237
  • 299
2
date('m/d/Y',strtotime($month . ' ' . $day . ' ' . $year));

The advantage of this is that you can choose how to format the date independent of how it is stored in your database: http://php.net/manual/en/function.date.php

DADU
  • 5,722
  • 6
  • 39
  • 62
1
echo $month . "/" . $day . "/" . $year;

Doing string concatenation.

or

echo "{$month}/{$day}/{$year}";

Doing string interpolation.

See the difference/performance of the two here.

Community
  • 1
  • 1
Mike Lewis
  • 61,841
  • 20
  • 140
  • 111