Get next date from day-month












0















I have one start date and I have next financial year end date's day and month. So based on this data how to get full financial year end date?



ie.



start date = 23rd January,2019
financial year end date's day = 31
financial year end date's month = 3

And I want full date as below :
financial year end date = 31st March,2019


Help me to how to get this date.










share|improve this question




















  • 1





    DateTime dateTime = new DateTime(Date.Now.AddYears(1).Year,financial year end date's month,financial year end date's day)

    – ikerbera
    Nov 23 '18 at 11:23











  • I have updated my question. How to do it with that?

    – iDipa
    Nov 23 '18 at 11:27











  • Do you have these strings as input ? You're going to have a bad time .. Maybe Humanizr has something on that but I doubt it. Deal with DateTime structure instead

    – Arthur Attout
    Nov 23 '18 at 11:29











  • Same code, Date.Now.AddYears(1).Year takes todays date, adds a year and gives you the int for the year of the new calculated date. If you still have day and month in the same variables it should work.

    – ikerbera
    Nov 23 '18 at 11:30











  • @iDipa, is your financial year end date is correct? please check it is not next year financial end date if start Date is = 23rd Nov 2019

    – Prasad Telkikar
    Nov 23 '18 at 11:30


















0















I have one start date and I have next financial year end date's day and month. So based on this data how to get full financial year end date?



ie.



start date = 23rd January,2019
financial year end date's day = 31
financial year end date's month = 3

And I want full date as below :
financial year end date = 31st March,2019


Help me to how to get this date.










share|improve this question




















  • 1





    DateTime dateTime = new DateTime(Date.Now.AddYears(1).Year,financial year end date's month,financial year end date's day)

    – ikerbera
    Nov 23 '18 at 11:23











  • I have updated my question. How to do it with that?

    – iDipa
    Nov 23 '18 at 11:27











  • Do you have these strings as input ? You're going to have a bad time .. Maybe Humanizr has something on that but I doubt it. Deal with DateTime structure instead

    – Arthur Attout
    Nov 23 '18 at 11:29











  • Same code, Date.Now.AddYears(1).Year takes todays date, adds a year and gives you the int for the year of the new calculated date. If you still have day and month in the same variables it should work.

    – ikerbera
    Nov 23 '18 at 11:30











  • @iDipa, is your financial year end date is correct? please check it is not next year financial end date if start Date is = 23rd Nov 2019

    – Prasad Telkikar
    Nov 23 '18 at 11:30
















0












0








0








I have one start date and I have next financial year end date's day and month. So based on this data how to get full financial year end date?



ie.



start date = 23rd January,2019
financial year end date's day = 31
financial year end date's month = 3

And I want full date as below :
financial year end date = 31st March,2019


Help me to how to get this date.










share|improve this question
















I have one start date and I have next financial year end date's day and month. So based on this data how to get full financial year end date?



ie.



start date = 23rd January,2019
financial year end date's day = 31
financial year end date's month = 3

And I want full date as below :
financial year end date = 31st March,2019


Help me to how to get this date.







c# .net date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 11:39









Konamiman

43k1598128




43k1598128










asked Nov 23 '18 at 11:20









iDipaiDipa

99416




99416








  • 1





    DateTime dateTime = new DateTime(Date.Now.AddYears(1).Year,financial year end date's month,financial year end date's day)

    – ikerbera
    Nov 23 '18 at 11:23











  • I have updated my question. How to do it with that?

    – iDipa
    Nov 23 '18 at 11:27











  • Do you have these strings as input ? You're going to have a bad time .. Maybe Humanizr has something on that but I doubt it. Deal with DateTime structure instead

    – Arthur Attout
    Nov 23 '18 at 11:29











  • Same code, Date.Now.AddYears(1).Year takes todays date, adds a year and gives you the int for the year of the new calculated date. If you still have day and month in the same variables it should work.

    – ikerbera
    Nov 23 '18 at 11:30











  • @iDipa, is your financial year end date is correct? please check it is not next year financial end date if start Date is = 23rd Nov 2019

    – Prasad Telkikar
    Nov 23 '18 at 11:30
















  • 1





    DateTime dateTime = new DateTime(Date.Now.AddYears(1).Year,financial year end date's month,financial year end date's day)

    – ikerbera
    Nov 23 '18 at 11:23











  • I have updated my question. How to do it with that?

    – iDipa
    Nov 23 '18 at 11:27











  • Do you have these strings as input ? You're going to have a bad time .. Maybe Humanizr has something on that but I doubt it. Deal with DateTime structure instead

    – Arthur Attout
    Nov 23 '18 at 11:29











  • Same code, Date.Now.AddYears(1).Year takes todays date, adds a year and gives you the int for the year of the new calculated date. If you still have day and month in the same variables it should work.

    – ikerbera
    Nov 23 '18 at 11:30











  • @iDipa, is your financial year end date is correct? please check it is not next year financial end date if start Date is = 23rd Nov 2019

    – Prasad Telkikar
    Nov 23 '18 at 11:30










1




1





DateTime dateTime = new DateTime(Date.Now.AddYears(1).Year,financial year end date's month,financial year end date's day)

– ikerbera
Nov 23 '18 at 11:23





DateTime dateTime = new DateTime(Date.Now.AddYears(1).Year,financial year end date's month,financial year end date's day)

– ikerbera
Nov 23 '18 at 11:23













I have updated my question. How to do it with that?

– iDipa
Nov 23 '18 at 11:27





I have updated my question. How to do it with that?

– iDipa
Nov 23 '18 at 11:27













Do you have these strings as input ? You're going to have a bad time .. Maybe Humanizr has something on that but I doubt it. Deal with DateTime structure instead

– Arthur Attout
Nov 23 '18 at 11:29





Do you have these strings as input ? You're going to have a bad time .. Maybe Humanizr has something on that but I doubt it. Deal with DateTime structure instead

– Arthur Attout
Nov 23 '18 at 11:29













Same code, Date.Now.AddYears(1).Year takes todays date, adds a year and gives you the int for the year of the new calculated date. If you still have day and month in the same variables it should work.

– ikerbera
Nov 23 '18 at 11:30





Same code, Date.Now.AddYears(1).Year takes todays date, adds a year and gives you the int for the year of the new calculated date. If you still have day and month in the same variables it should work.

– ikerbera
Nov 23 '18 at 11:30













@iDipa, is your financial year end date is correct? please check it is not next year financial end date if start Date is = 23rd Nov 2019

– Prasad Telkikar
Nov 23 '18 at 11:30







@iDipa, is your financial year end date is correct? please check it is not next year financial end date if start Date is = 23rd Nov 2019

– Prasad Telkikar
Nov 23 '18 at 11:30














3 Answers
3






active

oldest

votes


















3














Try, to allow for a variable start date:



DateTime startDate = new DateTime(2019,1,23);
DateTime financialYear = new DateTime(startDate.Year, 3,31);
if (startDate > financialYear)
{
financialYear = financialYear.AddYears(1);
}


And then format financialYear to the required format






share|improve this answer































    1














    var startDate = new DateTime(2019,1,23); //23rd January,2019
    var financialYearEndDay = 31;
    var financialYearEndMonth = 3;
    DateTime financialYear = new
    DateTime(date.Year,financialYearEndMonth,financialYearEndDay);
    if (startDate > financialYear)
    {
    financialYear = financialYear.AddYears(1);
    }





    share|improve this answer































      0














      If I understood correctly you just need a new DateTime object that takes the year from startDate, but has fixed day and month? Then assuming that you have startDate as a DateTime object already you just do:



      new DateTime(startDate.Year, financialYearEndMonth, financialYearEndDay)





      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%2f53445751%2fget-next-date-from-day-month%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        Try, to allow for a variable start date:



        DateTime startDate = new DateTime(2019,1,23);
        DateTime financialYear = new DateTime(startDate.Year, 3,31);
        if (startDate > financialYear)
        {
        financialYear = financialYear.AddYears(1);
        }


        And then format financialYear to the required format






        share|improve this answer




























          3














          Try, to allow for a variable start date:



          DateTime startDate = new DateTime(2019,1,23);
          DateTime financialYear = new DateTime(startDate.Year, 3,31);
          if (startDate > financialYear)
          {
          financialYear = financialYear.AddYears(1);
          }


          And then format financialYear to the required format






          share|improve this answer


























            3












            3








            3







            Try, to allow for a variable start date:



            DateTime startDate = new DateTime(2019,1,23);
            DateTime financialYear = new DateTime(startDate.Year, 3,31);
            if (startDate > financialYear)
            {
            financialYear = financialYear.AddYears(1);
            }


            And then format financialYear to the required format






            share|improve this answer













            Try, to allow for a variable start date:



            DateTime startDate = new DateTime(2019,1,23);
            DateTime financialYear = new DateTime(startDate.Year, 3,31);
            if (startDate > financialYear)
            {
            financialYear = financialYear.AddYears(1);
            }


            And then format financialYear to the required format







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 11:43









            Peter SmithPeter Smith

            3,67754168




            3,67754168

























                1














                var startDate = new DateTime(2019,1,23); //23rd January,2019
                var financialYearEndDay = 31;
                var financialYearEndMonth = 3;
                DateTime financialYear = new
                DateTime(date.Year,financialYearEndMonth,financialYearEndDay);
                if (startDate > financialYear)
                {
                financialYear = financialYear.AddYears(1);
                }





                share|improve this answer




























                  1














                  var startDate = new DateTime(2019,1,23); //23rd January,2019
                  var financialYearEndDay = 31;
                  var financialYearEndMonth = 3;
                  DateTime financialYear = new
                  DateTime(date.Year,financialYearEndMonth,financialYearEndDay);
                  if (startDate > financialYear)
                  {
                  financialYear = financialYear.AddYears(1);
                  }





                  share|improve this answer


























                    1












                    1








                    1







                    var startDate = new DateTime(2019,1,23); //23rd January,2019
                    var financialYearEndDay = 31;
                    var financialYearEndMonth = 3;
                    DateTime financialYear = new
                    DateTime(date.Year,financialYearEndMonth,financialYearEndDay);
                    if (startDate > financialYear)
                    {
                    financialYear = financialYear.AddYears(1);
                    }





                    share|improve this answer













                    var startDate = new DateTime(2019,1,23); //23rd January,2019
                    var financialYearEndDay = 31;
                    var financialYearEndMonth = 3;
                    DateTime financialYear = new
                    DateTime(date.Year,financialYearEndMonth,financialYearEndDay);
                    if (startDate > financialYear)
                    {
                    financialYear = financialYear.AddYears(1);
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 23 '18 at 11:40









                    HabeebHabeeb

                    3,82211825




                    3,82211825























                        0














                        If I understood correctly you just need a new DateTime object that takes the year from startDate, but has fixed day and month? Then assuming that you have startDate as a DateTime object already you just do:



                        new DateTime(startDate.Year, financialYearEndMonth, financialYearEndDay)





                        share|improve this answer




























                          0














                          If I understood correctly you just need a new DateTime object that takes the year from startDate, but has fixed day and month? Then assuming that you have startDate as a DateTime object already you just do:



                          new DateTime(startDate.Year, financialYearEndMonth, financialYearEndDay)





                          share|improve this answer


























                            0












                            0








                            0







                            If I understood correctly you just need a new DateTime object that takes the year from startDate, but has fixed day and month? Then assuming that you have startDate as a DateTime object already you just do:



                            new DateTime(startDate.Year, financialYearEndMonth, financialYearEndDay)





                            share|improve this answer













                            If I understood correctly you just need a new DateTime object that takes the year from startDate, but has fixed day and month? Then assuming that you have startDate as a DateTime object already you just do:



                            new DateTime(startDate.Year, financialYearEndMonth, financialYearEndDay)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 23 '18 at 11:41









                            KonamimanKonamiman

                            43k1598128




                            43k1598128






























                                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%2f53445751%2fget-next-date-from-day-month%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







                                這個網誌中的熱門文章

                                Hercules Kyvelos

                                Tangent Lines Diagram Along Smooth Curve

                                Yusuf al-Mu'taman ibn Hud