|
Posted by taps128 on 11/29/07 09:00
Jason Carlton wrote:
> I'm sure this is an easy one, but I can't seem to find it! I have the
> date and time as:
>
> # Nov 28, 2007, 11:11:14pm
> $timestamp = 20071128231114;
>
> In Perl, I would split this up as:
>
> my ($year, $month, $day, $hr, $min, $sec) = $timestamp =~ /(\d{4})(\d
> \d)(\d\d)(\d\d)(\d\d)(\d\d)/;
>
> How do I do the same thing in PHP? I know that I can use substr, of
> course, but there has to be a better way that I'm overlooking.
>
> TIA,
>
> Jason
I think you don't have a timestamp in the true sense, I think your
$timestamp variables shows an unformated date '2007-11-28 23:11:14'.
Which is what you looked for in your regular expression in perl, i think.
In php you can use:
$year=substr($timestamp,0,4);
$month=substr($timestamp,4,2);
$day=substr($timestamp,6,2);
$hour=substr($timestamp,8,2);
$minute=substr($timestamp,10,2);
$second=substr($timestamp,12,2);
I think that will solve your problem.
[Back to original message]
|