简体   繁体   中英

PHP date and time stamp

i'm busy with a wordpress module. With this module people can show domain extensions for sale.

But now, there are coming new extensions so I want to make an option which allows the user to enter the releasedate of the extension in the backend of the website. If the entered releasedate is today and this hour, customers are able to buy the extension by clicking on buy .

If the releasedate is tomorrow or later, there will be a warning text like "This exension isn't released yet, you can buy it at : $releasedate ".

Now i made dropdown menu's to select a date like 3/5/2014 and a hour like 2 'o clock or 3 'o clock or something else.

I put the selected date, which is a value for now, in the var $releasedateday $releasedatemonth $releasedateyear $releasedatehour .

I'm trying to make a timestamp, to make an if-statement like " `

if($releasedate =< $today) {

[*buy button*] }

else {
[This domain extension is going to release at $releasedate]`. }

Because I am not going to put down all the code of the dropdowns here, i give the variables a value. I have this but it doesn't work, can you guys please help me to make my values able to compare with the date and time of now?

<?php
$releasedatumhour = 14;
$releasedatumday = 14;
$releasedatummonth = 7;
$releasedatumyear = 2014;
$date = new DateTime($releasedatumday.'-'.$releasedatummaand.'-'.$releasedatumyear);
$releasedatum = $date->format('d-m-Y H:i') . "\n";
$releasetime = new DateTime($releasedatumuurs);
$releasedatum = $date->format('H') . "\n";
echo $releasedatum $releasetime.':00';
?>

To get the timestamp of the $date variable you can use the DateTime::getTimestamp() method

$release_ts = $date->getTimestamp(); //this would save the timestamp into $release_ts
$today = new DateTime('now')->getTimestamp(); //gets Timestamp of NOW

if($release_ts > $today) {
    ...
}

This should do the job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM