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,120
  • 11
  • 53
  • 71

4 Answers4

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

try this out :

echo "{$month}/{$day}/{$year}";
Naftali
  • 144,921
  • 39
  • 244
  • 303
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
  • 6,482
  • 7
  • 42
  • 64
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
  • 63,433
  • 20
  • 141
  • 111