Get Unix timestamp of specific date after another specific time
I can get the for example 19 March of specific date with this code:
$date = strtotime(" 19 March", $current_time);
For example if I gave the unix timestamp of 1st of January of 2010 as an input, It gave me 19 March of 2010. But also if I gave the unix timestamp of 20 March of 2010,I still get 19 March 2010. What I want is to get the next 19 March which in this case, It would be 19 March of 2011.
How can I do that?
php date strtotime
add a comment |
I can get the for example 19 March of specific date with this code:
$date = strtotime(" 19 March", $current_time);
For example if I gave the unix timestamp of 1st of January of 2010 as an input, It gave me 19 March of 2010. But also if I gave the unix timestamp of 20 March of 2010,I still get 19 March 2010. What I want is to get the next 19 March which in this case, It would be 19 March of 2011.
How can I do that?
php date strtotime
Google thestrtotime()
function, it's all on the php page.
– Epodax
Dec 23 '15 at 8:54
I've already read the strtotime(). I couldn't find anything for my problem. Maybe it didn't catch my eye. So If you have any resource I would be happy to have it. But right now this comment doesn't help me. @Epodax
– DrStein
Dec 23 '15 at 9:54
add a comment |
I can get the for example 19 March of specific date with this code:
$date = strtotime(" 19 March", $current_time);
For example if I gave the unix timestamp of 1st of January of 2010 as an input, It gave me 19 March of 2010. But also if I gave the unix timestamp of 20 March of 2010,I still get 19 March 2010. What I want is to get the next 19 March which in this case, It would be 19 March of 2011.
How can I do that?
php date strtotime
I can get the for example 19 March of specific date with this code:
$date = strtotime(" 19 March", $current_time);
For example if I gave the unix timestamp of 1st of January of 2010 as an input, It gave me 19 March of 2010. But also if I gave the unix timestamp of 20 March of 2010,I still get 19 March 2010. What I want is to get the next 19 March which in this case, It would be 19 March of 2011.
How can I do that?
php date strtotime
php date strtotime
asked Dec 23 '15 at 8:52


DrSteinDrStein
10412
10412
Google thestrtotime()
function, it's all on the php page.
– Epodax
Dec 23 '15 at 8:54
I've already read the strtotime(). I couldn't find anything for my problem. Maybe it didn't catch my eye. So If you have any resource I would be happy to have it. But right now this comment doesn't help me. @Epodax
– DrStein
Dec 23 '15 at 9:54
add a comment |
Google thestrtotime()
function, it's all on the php page.
– Epodax
Dec 23 '15 at 8:54
I've already read the strtotime(). I couldn't find anything for my problem. Maybe it didn't catch my eye. So If you have any resource I would be happy to have it. But right now this comment doesn't help me. @Epodax
– DrStein
Dec 23 '15 at 9:54
Google the
strtotime()
function, it's all on the php page.– Epodax
Dec 23 '15 at 8:54
Google the
strtotime()
function, it's all on the php page.– Epodax
Dec 23 '15 at 8:54
I've already read the strtotime(). I couldn't find anything for my problem. Maybe it didn't catch my eye. So If you have any resource I would be happy to have it. But right now this comment doesn't help me. @Epodax
– DrStein
Dec 23 '15 at 9:54
I've already read the strtotime(). I couldn't find anything for my problem. Maybe it didn't catch my eye. So If you have any resource I would be happy to have it. But right now this comment doesn't help me. @Epodax
– DrStein
Dec 23 '15 at 9:54
add a comment |
4 Answers
4
active
oldest
votes
You can do something like as
$get = "19 March";
$given_date = "01 January 2010";
$date_month = date('d F',strtotime($given_date));
$year = date('Y',strtotime($given_date));
if(strtotime($given_date) - strtotime($date_month) < 0){
echo date('l,d F Y',strtotime("$get $year"));
}else{
echo date('l,d F Y',strtotime("$get ".($year+1)));
}
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
add a comment |
Using PHP DateTime this can be achieved as follows:
// New DateTime object
$date = new DateTime('2010-03-19');
// Add a year
$date->add(new DateInterval('P1Y'));
// Output timestamp
echo $date->getTimestamp();
add a comment |
You should first get year
from specified date. Then after you can create 19 march
date with year and use strtotime()
to get timestamp.
//add format according to your current_time variable format
$date = DateTime::createFromFormat("Y-m-d", $current_time);
echo $date->format("Y");
$fixed_date = strtotime($date->format("Y")."-03-19");
add a comment |
You can specify how many days or week you want to add or subtract from a day, as well as set the time with these functions
$nextUpdate = new DateTime("+5 day 1:00 pm");
echo $nextUpdate->getTimestamp();
$nextWeek = new DateTime("+1 week 9:00 am");
echo $nextWeek->getTimestamp();
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%2f34431820%2fget-unix-timestamp-of-specific-date-after-another-specific-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do something like as
$get = "19 March";
$given_date = "01 January 2010";
$date_month = date('d F',strtotime($given_date));
$year = date('Y',strtotime($given_date));
if(strtotime($given_date) - strtotime($date_month) < 0){
echo date('l,d F Y',strtotime("$get $year"));
}else{
echo date('l,d F Y',strtotime("$get ".($year+1)));
}
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
add a comment |
You can do something like as
$get = "19 March";
$given_date = "01 January 2010";
$date_month = date('d F',strtotime($given_date));
$year = date('Y',strtotime($given_date));
if(strtotime($given_date) - strtotime($date_month) < 0){
echo date('l,d F Y',strtotime("$get $year"));
}else{
echo date('l,d F Y',strtotime("$get ".($year+1)));
}
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
add a comment |
You can do something like as
$get = "19 March";
$given_date = "01 January 2010";
$date_month = date('d F',strtotime($given_date));
$year = date('Y',strtotime($given_date));
if(strtotime($given_date) - strtotime($date_month) < 0){
echo date('l,d F Y',strtotime("$get $year"));
}else{
echo date('l,d F Y',strtotime("$get ".($year+1)));
}
You can do something like as
$get = "19 March";
$given_date = "01 January 2010";
$date_month = date('d F',strtotime($given_date));
$year = date('Y',strtotime($given_date));
if(strtotime($given_date) - strtotime($date_month) < 0){
echo date('l,d F Y',strtotime("$get $year"));
}else{
echo date('l,d F Y',strtotime("$get ".($year+1)));
}
answered Dec 23 '15 at 9:30


Narendrasingh SisodiaNarendrasingh Sisodia
18.1k43343
18.1k43343
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
add a comment |
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I assume one of the $given_date is $get? Also I liked to get the answer with just using strtotime, I guess there is not any way.
– DrStein
Dec 23 '15 at 9:51
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
I've posted an option to you to work around
– Narendrasingh Sisodia
Dec 23 '15 at 9:53
add a comment |
Using PHP DateTime this can be achieved as follows:
// New DateTime object
$date = new DateTime('2010-03-19');
// Add a year
$date->add(new DateInterval('P1Y'));
// Output timestamp
echo $date->getTimestamp();
add a comment |
Using PHP DateTime this can be achieved as follows:
// New DateTime object
$date = new DateTime('2010-03-19');
// Add a year
$date->add(new DateInterval('P1Y'));
// Output timestamp
echo $date->getTimestamp();
add a comment |
Using PHP DateTime this can be achieved as follows:
// New DateTime object
$date = new DateTime('2010-03-19');
// Add a year
$date->add(new DateInterval('P1Y'));
// Output timestamp
echo $date->getTimestamp();
Using PHP DateTime this can be achieved as follows:
// New DateTime object
$date = new DateTime('2010-03-19');
// Add a year
$date->add(new DateInterval('P1Y'));
// Output timestamp
echo $date->getTimestamp();
answered Dec 23 '15 at 9:02


PeterPeter
4,26643569
4,26643569
add a comment |
add a comment |
You should first get year
from specified date. Then after you can create 19 march
date with year and use strtotime()
to get timestamp.
//add format according to your current_time variable format
$date = DateTime::createFromFormat("Y-m-d", $current_time);
echo $date->format("Y");
$fixed_date = strtotime($date->format("Y")."-03-19");
add a comment |
You should first get year
from specified date. Then after you can create 19 march
date with year and use strtotime()
to get timestamp.
//add format according to your current_time variable format
$date = DateTime::createFromFormat("Y-m-d", $current_time);
echo $date->format("Y");
$fixed_date = strtotime($date->format("Y")."-03-19");
add a comment |
You should first get year
from specified date. Then after you can create 19 march
date with year and use strtotime()
to get timestamp.
//add format according to your current_time variable format
$date = DateTime::createFromFormat("Y-m-d", $current_time);
echo $date->format("Y");
$fixed_date = strtotime($date->format("Y")."-03-19");
You should first get year
from specified date. Then after you can create 19 march
date with year and use strtotime()
to get timestamp.
//add format according to your current_time variable format
$date = DateTime::createFromFormat("Y-m-d", $current_time);
echo $date->format("Y");
$fixed_date = strtotime($date->format("Y")."-03-19");
answered Dec 23 '15 at 9:00
ParixitParixit
3,34532852
3,34532852
add a comment |
add a comment |
You can specify how many days or week you want to add or subtract from a day, as well as set the time with these functions
$nextUpdate = new DateTime("+5 day 1:00 pm");
echo $nextUpdate->getTimestamp();
$nextWeek = new DateTime("+1 week 9:00 am");
echo $nextWeek->getTimestamp();
add a comment |
You can specify how many days or week you want to add or subtract from a day, as well as set the time with these functions
$nextUpdate = new DateTime("+5 day 1:00 pm");
echo $nextUpdate->getTimestamp();
$nextWeek = new DateTime("+1 week 9:00 am");
echo $nextWeek->getTimestamp();
add a comment |
You can specify how many days or week you want to add or subtract from a day, as well as set the time with these functions
$nextUpdate = new DateTime("+5 day 1:00 pm");
echo $nextUpdate->getTimestamp();
$nextWeek = new DateTime("+1 week 9:00 am");
echo $nextWeek->getTimestamp();
You can specify how many days or week you want to add or subtract from a day, as well as set the time with these functions
$nextUpdate = new DateTime("+5 day 1:00 pm");
echo $nextUpdate->getTimestamp();
$nextWeek = new DateTime("+1 week 9:00 am");
echo $nextWeek->getTimestamp();
edited Nov 20 '18 at 3:06
answered Aug 10 '18 at 18:06
Omar ZairiOmar Zairi
414
414
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%2f34431820%2fget-unix-timestamp-of-specific-date-after-another-specific-time%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
Google the
strtotime()
function, it's all on the php page.– Epodax
Dec 23 '15 at 8:54
I've already read the strtotime(). I couldn't find anything for my problem. Maybe it didn't catch my eye. So If you have any resource I would be happy to have it. But right now this comment doesn't help me. @Epodax
– DrStein
Dec 23 '15 at 9:54