-3

I have a column named "timestamp" in my DB with datatype timestamp and standard CURRENT_TIMESTAMP.

When I echo it (echo $row['timestamp'];) i get this:

2016-01-18 21:06:37 
2016-01-19 12:32:16 
2016-01-19 20:52:41

But I want it to turn out like this:

2016-01-18
2016-01-19
2016-01-19

How should I do that? Strftime or something?

saltcracker
  • 321
  • 3
  • 17
  • 3
    the number of posts on changing date format has reached such a critical mass they form their own black hole –  Jan 19 '16 at 22:18

2 Answers2

1

Use substr:

substr($row['timestamp'],0,10)

This will output the first 10 characters of your string.

Svea
  • 267
  • 1
  • 8
1

echo date('Y-m-d', strtotime(str_replace('-','/', $row['timestamp'])));

AndrewK
  • 1,223
  • 2
  • 16
  • 25
  • `Notice: A non well formed numeric value encountered in *path to file* on line 30 1970-01-01`. Thanks for trying the help me out though! :) – saltcracker Jan 19 '16 at 22:25
  • it looks like the - in the format causes an issue, try this: echo date('Y-m-d', strtotime(str_replace('-','/', $row['timestamp']))); – AndrewK Jan 19 '16 at 22:30