Dodinas
Dodinas

Reputation: 6805

PHP Convert Unix time to ISO and Subtract an Hour

I'm restructuring my MySQL database, which has several columns in Unix format.

Because I already have several rows in the database in Unix format. How can I convert the Unix fields to iso, and then subtract an hour using PHP?

For example, I currently have:

<?php
 $unix_time = 1267840800;
 $conversion = date("c", $unix_time);

The above code spits out:

2010-03-05T20:00:00-06:00

My question is, how can I take it a step further and subtract an hour and just have:

2010-03-05 19:00:00

Upvotes: 1

Views: 1153

Answers (2)

Eric Butera
Eric Butera

Reputation: 638

You could also take your timestamp and say strtotime("-1 hour", 1267840800).

Upvotes: 2

Pekka
Pekka

Reputation: 449525

<?php
 $unix_time = 1267840800;
 $one_hour = 60 * 60;

 $conversion = date("Y-m-d h:i:s", $unix_time - $one_hour);

Upvotes: 3

Related Questions