Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get timestamp of noon PHP

Tags:

php

Suppose I've got a timestamp, X.

Using PHP, how can I find the timestamp that represents noon of the day that X is from?

I guess I would need to convert X to a date, extract the day, and then convert noon from that day to a timestamp. Is there an easy way to do this in PHP?

like image 635
Andrew Avatar asked Dec 01 '22 05:12

Andrew


2 Answers

strtotime('noon', $timestamp) should work

like image 52
simshaun Avatar answered Dec 06 '22 12:12

simshaun


<?php
$timestamp = 1346343553;
$date = getdate($timestamp);

$noon = mktime ( 12, 00, 00, $date['mon'], $date['day'], $date['year'] );

print $noon;
print date(DATE_RSS, $noon);

Of course, this goes without saying, but timezones are not factored at all. Also, strtotime() is probably the preferred method, but getdate() doesn't get enough love!

like image 28
MetalFrog Avatar answered Dec 06 '22 12:12

MetalFrog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!