Check if given time minus now time is less than 60 minutes using php
I have read a lot here, and tried a lot, but I didn't get it :(
I have:
$end = new DateTime('22:00');
$now = new DateTime();
if(($end - $now) < 60)
{
$bijnaTijd = "bijnaTijdJa";
}
I want to see if the difference between the $end
and the current time is less than 60
minutes. Can anybody help me out?
php datetime time
add a comment |
I have read a lot here, and tried a lot, but I didn't get it :(
I have:
$end = new DateTime('22:00');
$now = new DateTime();
if(($end - $now) < 60)
{
$bijnaTijd = "bijnaTijdJa";
}
I want to see if the difference between the $end
and the current time is less than 60
minutes. Can anybody help me out?
php datetime time
add a comment |
I have read a lot here, and tried a lot, but I didn't get it :(
I have:
$end = new DateTime('22:00');
$now = new DateTime();
if(($end - $now) < 60)
{
$bijnaTijd = "bijnaTijdJa";
}
I want to see if the difference between the $end
and the current time is less than 60
minutes. Can anybody help me out?
php datetime time
I have read a lot here, and tried a lot, but I didn't get it :(
I have:
$end = new DateTime('22:00');
$now = new DateTime();
if(($end - $now) < 60)
{
$bijnaTijd = "bijnaTijdJa";
}
I want to see if the difference between the $end
and the current time is less than 60
minutes. Can anybody help me out?
php datetime time
php datetime time
edited Nov 25 '18 at 4:51
Mohammad
15.4k123461
15.4k123461
asked Nov 24 '18 at 20:55
franky555franky555
104
104
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You need to get timestamp from DateTime
object using getTimestamp()
and compare timestamps with each other.
Note that timestamp is in second so i used 60*60
to converting minutes to seconds.
$end = new DateTime('22:00');
$now = new DateTime();
if (($end->getTimestamp() - $now->getTimestamp()) < 60*60){
// do something
}
Also you can dates function instead of DateTime
class.
if (strtotime('22:00') - time() < 60*60){
// do something
}
add a comment |
please check this code , hope it solve your problem
<?php
$end = new DateTime('22:00');
$new_end = strtotime($end->format('Hi')); //convert to string
$end_h = idate('h', $new_end); //get the hour
$end_h = str_pad($end_h, 2, 0, STR_PAD_RIGHT);
$end_m = idate('i', $new_end);
$end_m = str_pad($end_m, 2, 0, STR_PAD_LEFT); //get leading zero for above minutes 10
$time_end = $end_h.''.$end_m;
$now = new DateTime();
$new_now = strtotime($now->format('Hi'));
$now_h = idate('h', $new_now);
$now_h = str_pad($now_h, 2, 0, STR_PAD_RIGHT);
$now_m = idate('i', $new_now);
$now_m = str_pad($now_m, 2, 0, STR_PAD_LEFT);
$time_now = $now_h.''.$now_m;
echo ($time_end - $time_now); //get the result do your logic after this code
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462285%2fcheck-if-given-time-minus-now-time-is-less-than-60-minutes-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to get timestamp from DateTime
object using getTimestamp()
and compare timestamps with each other.
Note that timestamp is in second so i used 60*60
to converting minutes to seconds.
$end = new DateTime('22:00');
$now = new DateTime();
if (($end->getTimestamp() - $now->getTimestamp()) < 60*60){
// do something
}
Also you can dates function instead of DateTime
class.
if (strtotime('22:00') - time() < 60*60){
// do something
}
add a comment |
You need to get timestamp from DateTime
object using getTimestamp()
and compare timestamps with each other.
Note that timestamp is in second so i used 60*60
to converting minutes to seconds.
$end = new DateTime('22:00');
$now = new DateTime();
if (($end->getTimestamp() - $now->getTimestamp()) < 60*60){
// do something
}
Also you can dates function instead of DateTime
class.
if (strtotime('22:00') - time() < 60*60){
// do something
}
add a comment |
You need to get timestamp from DateTime
object using getTimestamp()
and compare timestamps with each other.
Note that timestamp is in second so i used 60*60
to converting minutes to seconds.
$end = new DateTime('22:00');
$now = new DateTime();
if (($end->getTimestamp() - $now->getTimestamp()) < 60*60){
// do something
}
Also you can dates function instead of DateTime
class.
if (strtotime('22:00') - time() < 60*60){
// do something
}
You need to get timestamp from DateTime
object using getTimestamp()
and compare timestamps with each other.
Note that timestamp is in second so i used 60*60
to converting minutes to seconds.
$end = new DateTime('22:00');
$now = new DateTime();
if (($end->getTimestamp() - $now->getTimestamp()) < 60*60){
// do something
}
Also you can dates function instead of DateTime
class.
if (strtotime('22:00') - time() < 60*60){
// do something
}
answered Nov 25 '18 at 4:49
MohammadMohammad
15.4k123461
15.4k123461
add a comment |
add a comment |
please check this code , hope it solve your problem
<?php
$end = new DateTime('22:00');
$new_end = strtotime($end->format('Hi')); //convert to string
$end_h = idate('h', $new_end); //get the hour
$end_h = str_pad($end_h, 2, 0, STR_PAD_RIGHT);
$end_m = idate('i', $new_end);
$end_m = str_pad($end_m, 2, 0, STR_PAD_LEFT); //get leading zero for above minutes 10
$time_end = $end_h.''.$end_m;
$now = new DateTime();
$new_now = strtotime($now->format('Hi'));
$now_h = idate('h', $new_now);
$now_h = str_pad($now_h, 2, 0, STR_PAD_RIGHT);
$now_m = idate('i', $new_now);
$now_m = str_pad($now_m, 2, 0, STR_PAD_LEFT);
$time_now = $now_h.''.$now_m;
echo ($time_end - $time_now); //get the result do your logic after this code
add a comment |
please check this code , hope it solve your problem
<?php
$end = new DateTime('22:00');
$new_end = strtotime($end->format('Hi')); //convert to string
$end_h = idate('h', $new_end); //get the hour
$end_h = str_pad($end_h, 2, 0, STR_PAD_RIGHT);
$end_m = idate('i', $new_end);
$end_m = str_pad($end_m, 2, 0, STR_PAD_LEFT); //get leading zero for above minutes 10
$time_end = $end_h.''.$end_m;
$now = new DateTime();
$new_now = strtotime($now->format('Hi'));
$now_h = idate('h', $new_now);
$now_h = str_pad($now_h, 2, 0, STR_PAD_RIGHT);
$now_m = idate('i', $new_now);
$now_m = str_pad($now_m, 2, 0, STR_PAD_LEFT);
$time_now = $now_h.''.$now_m;
echo ($time_end - $time_now); //get the result do your logic after this code
add a comment |
please check this code , hope it solve your problem
<?php
$end = new DateTime('22:00');
$new_end = strtotime($end->format('Hi')); //convert to string
$end_h = idate('h', $new_end); //get the hour
$end_h = str_pad($end_h, 2, 0, STR_PAD_RIGHT);
$end_m = idate('i', $new_end);
$end_m = str_pad($end_m, 2, 0, STR_PAD_LEFT); //get leading zero for above minutes 10
$time_end = $end_h.''.$end_m;
$now = new DateTime();
$new_now = strtotime($now->format('Hi'));
$now_h = idate('h', $new_now);
$now_h = str_pad($now_h, 2, 0, STR_PAD_RIGHT);
$now_m = idate('i', $new_now);
$now_m = str_pad($now_m, 2, 0, STR_PAD_LEFT);
$time_now = $now_h.''.$now_m;
echo ($time_end - $time_now); //get the result do your logic after this code
please check this code , hope it solve your problem
<?php
$end = new DateTime('22:00');
$new_end = strtotime($end->format('Hi')); //convert to string
$end_h = idate('h', $new_end); //get the hour
$end_h = str_pad($end_h, 2, 0, STR_PAD_RIGHT);
$end_m = idate('i', $new_end);
$end_m = str_pad($end_m, 2, 0, STR_PAD_LEFT); //get leading zero for above minutes 10
$time_end = $end_h.''.$end_m;
$now = new DateTime();
$new_now = strtotime($now->format('Hi'));
$now_h = idate('h', $new_now);
$now_h = str_pad($now_h, 2, 0, STR_PAD_RIGHT);
$now_m = idate('i', $new_now);
$now_m = str_pad($now_m, 2, 0, STR_PAD_LEFT);
$time_now = $now_h.''.$now_m;
echo ($time_end - $time_now); //get the result do your logic after this code
answered Nov 24 '18 at 21:34
rheeantzrheeantz
691311
691311
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462285%2fcheck-if-given-time-minus-now-time-is-less-than-60-minutes-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown