tags:

views:

152

answers:

4

I'm trying to take timestamps in this format:

2009-11-16T14:05:22-08:00

and make turn them into something like

2009-11-16

How do I remove everything after the "T"?

+3  A: 

Assuming they're all in that format, the easiest way is:

$result = substr($timestamp,0,10);

Where timestamp is your starting timestamp and result is your modified timestamp.

Travis
+1 for simplicity
Rubens Farias
I considered that, but won't it be a problem if we were in a month with one digit or in the first few days of this month? Wouldn't that screw it up?
pg
one-digit months and days will probably have leading zeros, like the '05' in '14:05:22' in your example.
yjerem
format that format (ISO8601 with full-date AND full-time), you'll need always to receive a two-digit day and month
Rubens Farias
+6  A: 

Maybe this works:

date('Y-m-d', strtotime('2009-11-16T14:05:22-08:00'));
powtac
+1  A: 

You could use explode():

list($date) = explode('T', '2009-11-16T14:05:22-08:00');

$date would now be '2009-11-16'.

yjerem
+1  A: 

Since the OP tagged it as a php and regex question, I'll give him a php and regex answer:

$result = preg_replace("/T.*/", "", $timestamp);
PaulC
+1 for sticking to the question
kemp