1

Possible Duplicate:
Date to timestamp (PHP)?

How do I get the current time in seconds since 1st january 1970 in php?

does the dateTime object support anything since as

$date1 = new DateTime("01/01/1970");   
$return = since($date1, date.now());

The problem I get here is I could just do something like ((minutes=hours *60)*60)

Is there a nicer way?

Community
  • 1
  • 1
David
  • 18,969
  • 28
  • 104
  • 128
  • Have you tried a simple `time()` call? – Bojangles May 17 '11 at 08:52
  • 1
    `$dateTime = new DateTime; echo $dateTime->format('U');` – Gordon May 17 '11 at 08:54
  • @Gordon The reason I didn't think this was a duplicate is because I want to know if my since() function is correct – David May 17 '11 at 08:59
  • your `since` function is superfluous. Either use `strtotime` or use the DateTime API. Also see [Difference between 2 dates in seconds](http://stackoverflow.com/questions/5988450/difference-between-2-dates-in-seconds) – Gordon May 17 '11 at 09:02

3 Answers3

2

You can use the time() function: http://php.net/manual/en/function.time.php

kapa
  • 75,446
  • 20
  • 155
  • 173
Fabrizio D'Ammassa
  • 4,699
  • 24
  • 32
  • ah, but this link doesn't appear to have anything with regards to a since() function, I only guessed at that method above as I couldn't find anything on it on first look – David May 17 '11 at 09:01
0

time()
Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Alex Pliutau
  • 20,640
  • 26
  • 107
  • 142
0

$_SERVER['REQUEST_TIME']; is a pretty light way to do it, if your server supports it. Otherwise you have the usual time() / strtotime() functions. Also, why is there javascript in your PHP?

Aaria Carter-Weir
  • 1,579
  • 10
  • 17