Get Unix timestamp of specific date after another specific time












-2















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?










share|improve this question























  • 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
















-2















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?










share|improve this question























  • 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














-2












-2








-2








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 23 '15 at 8:52









DrSteinDrStein

10412




10412













  • 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



















  • 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

















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












4 Answers
4






active

oldest

votes


















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)));
}





share|improve this answer
























  • 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



















3














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();





share|improve this answer































    0














    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");





    share|improve this answer































      0














      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();





      share|improve this answer

























        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
        });


        }
        });














        draft saved

        draft discarded


















        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









        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)));
        }





        share|improve this answer
























        • 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
















        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)));
        }





        share|improve this answer
























        • 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














        1












        1








        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)));
        }





        share|improve this answer













        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)));
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        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



















        • 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













        3














        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();





        share|improve this answer




























          3














          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();





          share|improve this answer


























            3












            3








            3







            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();





            share|improve this answer













            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();






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 23 '15 at 9:02









            PeterPeter

            4,26643569




            4,26643569























                0














                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");





                share|improve this answer




























                  0














                  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");





                  share|improve this answer


























                    0












                    0








                    0







                    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");





                    share|improve this answer













                    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");






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 23 '15 at 9:00









                    ParixitParixit

                    3,34532852




                    3,34532852























                        0














                        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();





                        share|improve this answer






























                          0














                          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();





                          share|improve this answer




























                            0












                            0








                            0







                            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();





                            share|improve this answer















                            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();






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 20 '18 at 3:06

























                            answered Aug 10 '18 at 18:06









                            Omar ZairiOmar Zairi

                            414




                            414






























                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                MongoDB - Not Authorized To Execute Command

                                How to fix TextFormField cause rebuild widget in Flutter

                                in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith