Why are both Nov 4 and Nov 5 2018 showing as Sunday?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I have a small piece of code which is displaying the Day of the week which is part of a larger method.



Date StartDate = Date.newInstance(2018, 11, 4);
Datetime StartDateDt = Datetime.newinstance(StartDate.year(),StartDate.month(),StartDate.day());
System.debug(StartDateDt);
System.debug(StartDateDt.format('EEEE') );
StartDateDt = StartDateDt.addDays(1);
System.debug(StartDateDt);
System.debug(StartDateDt.format('EEEE') );


If you look at the debug on the dev console



enter image description here



Any thoughts on what is happening here?



Update



if i was using GMT like what @Oleksandr Berehovskiy suggested then i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday



What i wanted was if i was running the code from the users locale then we should get the weekday from user's locale and not GMT



Interestingly the issue is only if the start date is given as 4th Nov. If i give the start date as 5 nov then it works fine



enter image description here










share|improve this question





























    up vote
    1
    down vote

    favorite












    I have a small piece of code which is displaying the Day of the week which is part of a larger method.



    Date StartDate = Date.newInstance(2018, 11, 4);
    Datetime StartDateDt = Datetime.newinstance(StartDate.year(),StartDate.month(),StartDate.day());
    System.debug(StartDateDt);
    System.debug(StartDateDt.format('EEEE') );
    StartDateDt = StartDateDt.addDays(1);
    System.debug(StartDateDt);
    System.debug(StartDateDt.format('EEEE') );


    If you look at the debug on the dev console



    enter image description here



    Any thoughts on what is happening here?



    Update



    if i was using GMT like what @Oleksandr Berehovskiy suggested then i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday



    What i wanted was if i was running the code from the users locale then we should get the weekday from user's locale and not GMT



    Interestingly the issue is only if the start date is given as 4th Nov. If i give the start date as 5 nov then it works fine



    enter image description here










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a small piece of code which is displaying the Day of the week which is part of a larger method.



      Date StartDate = Date.newInstance(2018, 11, 4);
      Datetime StartDateDt = Datetime.newinstance(StartDate.year(),StartDate.month(),StartDate.day());
      System.debug(StartDateDt);
      System.debug(StartDateDt.format('EEEE') );
      StartDateDt = StartDateDt.addDays(1);
      System.debug(StartDateDt);
      System.debug(StartDateDt.format('EEEE') );


      If you look at the debug on the dev console



      enter image description here



      Any thoughts on what is happening here?



      Update



      if i was using GMT like what @Oleksandr Berehovskiy suggested then i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday



      What i wanted was if i was running the code from the users locale then we should get the weekday from user's locale and not GMT



      Interestingly the issue is only if the start date is given as 4th Nov. If i give the start date as 5 nov then it works fine



      enter image description here










      share|improve this question















      I have a small piece of code which is displaying the Day of the week which is part of a larger method.



      Date StartDate = Date.newInstance(2018, 11, 4);
      Datetime StartDateDt = Datetime.newinstance(StartDate.year(),StartDate.month(),StartDate.day());
      System.debug(StartDateDt);
      System.debug(StartDateDt.format('EEEE') );
      StartDateDt = StartDateDt.addDays(1);
      System.debug(StartDateDt);
      System.debug(StartDateDt.format('EEEE') );


      If you look at the debug on the dev console



      enter image description here



      Any thoughts on what is happening here?



      Update



      if i was using GMT like what @Oleksandr Berehovskiy suggested then i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday



      What i wanted was if i was running the code from the users locale then we should get the weekday from user's locale and not GMT



      Interestingly the issue is only if the start date is given as 4th Nov. If i give the start date as 5 nov then it works fine



      enter image description here







      apex datetime






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 54 mins ago

























      asked 2 hours ago









      Prady

      6,4631885168




      6,4631885168




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          The reason of such behavior is daylight saving time offset.



          You are doing everything okay. Result is expected with Datetime class. Your user's timezone is America/Chicago. According to Daylight Saving Time Changes 2018 article, 4-th of November was a day, when clock went back 1 hour.




          Sunday, 4 November 2018, 02:00:00 clocks were turned backward 1 hour to



          Sunday, 4 November 2018, 01:00:00 local standard time instead.




          I have simplified your code to the following.



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);

          //DEBUG|myDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 00:00:00
          System.debug('myDateTime.format(yyyy-MM-dd HH:mm:ss):' + myDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-04 05:00:00
          System.debug('myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + myDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));

          Datetime newDateTime = myDateTime.addDays(1);

          //DEBUG|newDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 23:00:00
          System.debug('newDateTime.format(yyyy-MM-dd HH:mm:ss):' + newDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //|DEBUG|newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-05 05:00:00
          System.debug('newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + newDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);


          here you constructing local Chicago time 4-th of November 00:00:00



          after 2 hours, it is 02:00:00 and immediately time goes back 1 hour and it becomes 01:00:00 time. So you have not 24 hours per day, but 25.



          And looks like Datetime.addDays method adds 24 hours to Datetime and that is why after myDateTime.addDays(1) you have 2018-11-04 23:00:00. If you add 25 hours to it, you will get expected 2018-11-05 00:00:00 and Monday result.




          What final conclusion I did from current case.



          If you don't have to work with/get/manipulate with hours, minutes and seconds - always use Date class. Because it adds days correctly with all daylight saving time offsets.



          Date myDate = Date.newInstance(2018, 11, 4);

          //DEBUG|myDate.format(yyyy-MM-dd):11/4/2018
          System.debug('myDate.format(yyyy-MM-dd):' + myDate.format());

          Date newMyDate = myDate.addDays(1);

          //DEBUG|newMyDate.format:11/5/2018
          System.debug('newMyDate.format:' + newMyDate.format());
          DateTime newMyDateTime = DateTime.newInstance(newMyDate.year(), newMyDate.month(), newMyDate.day());

          //newMyDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-05 00:00:00
          System.debug('newMyDateTime.format(yyyy-MM-dd HH:mm:ss):' + newMyDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|newMyDateTime.format(EEEE):Monday
          System.debug('newMyDateTime.format(EEEE):' + newMyDateTime.format('EEEE'));


          from upper snippet, we convert Date to Datetime at the latest step, where we need to know what is a day of the week. But all manipulations we did with Date class






          share|improve this answer






















          • I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
            – Prady
            2 hours ago










          • @Prady what timezone do you have on your user?
            – Oleksandr Berehovskiy
            2 hours ago










          • (GMT-06:00) Central Standard Time (America/Chicago)
            – Prady
            2 hours ago










          • @Prady I have updated my answer.
            – Oleksandr Berehovskiy
            23 mins ago










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          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',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fsalesforce.stackexchange.com%2fquestions%2f238465%2fwhy-are-both-nov-4-and-nov-5-2018-showing-as-sunday%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote













          The reason of such behavior is daylight saving time offset.



          You are doing everything okay. Result is expected with Datetime class. Your user's timezone is America/Chicago. According to Daylight Saving Time Changes 2018 article, 4-th of November was a day, when clock went back 1 hour.




          Sunday, 4 November 2018, 02:00:00 clocks were turned backward 1 hour to



          Sunday, 4 November 2018, 01:00:00 local standard time instead.




          I have simplified your code to the following.



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);

          //DEBUG|myDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 00:00:00
          System.debug('myDateTime.format(yyyy-MM-dd HH:mm:ss):' + myDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-04 05:00:00
          System.debug('myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + myDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));

          Datetime newDateTime = myDateTime.addDays(1);

          //DEBUG|newDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 23:00:00
          System.debug('newDateTime.format(yyyy-MM-dd HH:mm:ss):' + newDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //|DEBUG|newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-05 05:00:00
          System.debug('newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + newDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);


          here you constructing local Chicago time 4-th of November 00:00:00



          after 2 hours, it is 02:00:00 and immediately time goes back 1 hour and it becomes 01:00:00 time. So you have not 24 hours per day, but 25.



          And looks like Datetime.addDays method adds 24 hours to Datetime and that is why after myDateTime.addDays(1) you have 2018-11-04 23:00:00. If you add 25 hours to it, you will get expected 2018-11-05 00:00:00 and Monday result.




          What final conclusion I did from current case.



          If you don't have to work with/get/manipulate with hours, minutes and seconds - always use Date class. Because it adds days correctly with all daylight saving time offsets.



          Date myDate = Date.newInstance(2018, 11, 4);

          //DEBUG|myDate.format(yyyy-MM-dd):11/4/2018
          System.debug('myDate.format(yyyy-MM-dd):' + myDate.format());

          Date newMyDate = myDate.addDays(1);

          //DEBUG|newMyDate.format:11/5/2018
          System.debug('newMyDate.format:' + newMyDate.format());
          DateTime newMyDateTime = DateTime.newInstance(newMyDate.year(), newMyDate.month(), newMyDate.day());

          //newMyDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-05 00:00:00
          System.debug('newMyDateTime.format(yyyy-MM-dd HH:mm:ss):' + newMyDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|newMyDateTime.format(EEEE):Monday
          System.debug('newMyDateTime.format(EEEE):' + newMyDateTime.format('EEEE'));


          from upper snippet, we convert Date to Datetime at the latest step, where we need to know what is a day of the week. But all manipulations we did with Date class






          share|improve this answer






















          • I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
            – Prady
            2 hours ago










          • @Prady what timezone do you have on your user?
            – Oleksandr Berehovskiy
            2 hours ago










          • (GMT-06:00) Central Standard Time (America/Chicago)
            – Prady
            2 hours ago










          • @Prady I have updated my answer.
            – Oleksandr Berehovskiy
            23 mins ago














          up vote
          3
          down vote













          The reason of such behavior is daylight saving time offset.



          You are doing everything okay. Result is expected with Datetime class. Your user's timezone is America/Chicago. According to Daylight Saving Time Changes 2018 article, 4-th of November was a day, when clock went back 1 hour.




          Sunday, 4 November 2018, 02:00:00 clocks were turned backward 1 hour to



          Sunday, 4 November 2018, 01:00:00 local standard time instead.




          I have simplified your code to the following.



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);

          //DEBUG|myDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 00:00:00
          System.debug('myDateTime.format(yyyy-MM-dd HH:mm:ss):' + myDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-04 05:00:00
          System.debug('myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + myDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));

          Datetime newDateTime = myDateTime.addDays(1);

          //DEBUG|newDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 23:00:00
          System.debug('newDateTime.format(yyyy-MM-dd HH:mm:ss):' + newDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //|DEBUG|newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-05 05:00:00
          System.debug('newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + newDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);


          here you constructing local Chicago time 4-th of November 00:00:00



          after 2 hours, it is 02:00:00 and immediately time goes back 1 hour and it becomes 01:00:00 time. So you have not 24 hours per day, but 25.



          And looks like Datetime.addDays method adds 24 hours to Datetime and that is why after myDateTime.addDays(1) you have 2018-11-04 23:00:00. If you add 25 hours to it, you will get expected 2018-11-05 00:00:00 and Monday result.




          What final conclusion I did from current case.



          If you don't have to work with/get/manipulate with hours, minutes and seconds - always use Date class. Because it adds days correctly with all daylight saving time offsets.



          Date myDate = Date.newInstance(2018, 11, 4);

          //DEBUG|myDate.format(yyyy-MM-dd):11/4/2018
          System.debug('myDate.format(yyyy-MM-dd):' + myDate.format());

          Date newMyDate = myDate.addDays(1);

          //DEBUG|newMyDate.format:11/5/2018
          System.debug('newMyDate.format:' + newMyDate.format());
          DateTime newMyDateTime = DateTime.newInstance(newMyDate.year(), newMyDate.month(), newMyDate.day());

          //newMyDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-05 00:00:00
          System.debug('newMyDateTime.format(yyyy-MM-dd HH:mm:ss):' + newMyDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|newMyDateTime.format(EEEE):Monday
          System.debug('newMyDateTime.format(EEEE):' + newMyDateTime.format('EEEE'));


          from upper snippet, we convert Date to Datetime at the latest step, where we need to know what is a day of the week. But all manipulations we did with Date class






          share|improve this answer






















          • I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
            – Prady
            2 hours ago










          • @Prady what timezone do you have on your user?
            – Oleksandr Berehovskiy
            2 hours ago










          • (GMT-06:00) Central Standard Time (America/Chicago)
            – Prady
            2 hours ago










          • @Prady I have updated my answer.
            – Oleksandr Berehovskiy
            23 mins ago












          up vote
          3
          down vote










          up vote
          3
          down vote









          The reason of such behavior is daylight saving time offset.



          You are doing everything okay. Result is expected with Datetime class. Your user's timezone is America/Chicago. According to Daylight Saving Time Changes 2018 article, 4-th of November was a day, when clock went back 1 hour.




          Sunday, 4 November 2018, 02:00:00 clocks were turned backward 1 hour to



          Sunday, 4 November 2018, 01:00:00 local standard time instead.




          I have simplified your code to the following.



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);

          //DEBUG|myDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 00:00:00
          System.debug('myDateTime.format(yyyy-MM-dd HH:mm:ss):' + myDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-04 05:00:00
          System.debug('myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + myDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));

          Datetime newDateTime = myDateTime.addDays(1);

          //DEBUG|newDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 23:00:00
          System.debug('newDateTime.format(yyyy-MM-dd HH:mm:ss):' + newDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //|DEBUG|newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-05 05:00:00
          System.debug('newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + newDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);


          here you constructing local Chicago time 4-th of November 00:00:00



          after 2 hours, it is 02:00:00 and immediately time goes back 1 hour and it becomes 01:00:00 time. So you have not 24 hours per day, but 25.



          And looks like Datetime.addDays method adds 24 hours to Datetime and that is why after myDateTime.addDays(1) you have 2018-11-04 23:00:00. If you add 25 hours to it, you will get expected 2018-11-05 00:00:00 and Monday result.




          What final conclusion I did from current case.



          If you don't have to work with/get/manipulate with hours, minutes and seconds - always use Date class. Because it adds days correctly with all daylight saving time offsets.



          Date myDate = Date.newInstance(2018, 11, 4);

          //DEBUG|myDate.format(yyyy-MM-dd):11/4/2018
          System.debug('myDate.format(yyyy-MM-dd):' + myDate.format());

          Date newMyDate = myDate.addDays(1);

          //DEBUG|newMyDate.format:11/5/2018
          System.debug('newMyDate.format:' + newMyDate.format());
          DateTime newMyDateTime = DateTime.newInstance(newMyDate.year(), newMyDate.month(), newMyDate.day());

          //newMyDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-05 00:00:00
          System.debug('newMyDateTime.format(yyyy-MM-dd HH:mm:ss):' + newMyDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|newMyDateTime.format(EEEE):Monday
          System.debug('newMyDateTime.format(EEEE):' + newMyDateTime.format('EEEE'));


          from upper snippet, we convert Date to Datetime at the latest step, where we need to know what is a day of the week. But all manipulations we did with Date class






          share|improve this answer














          The reason of such behavior is daylight saving time offset.



          You are doing everything okay. Result is expected with Datetime class. Your user's timezone is America/Chicago. According to Daylight Saving Time Changes 2018 article, 4-th of November was a day, when clock went back 1 hour.




          Sunday, 4 November 2018, 02:00:00 clocks were turned backward 1 hour to



          Sunday, 4 November 2018, 01:00:00 local standard time instead.




          I have simplified your code to the following.



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);

          //DEBUG|myDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 00:00:00
          System.debug('myDateTime.format(yyyy-MM-dd HH:mm:ss):' + myDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-04 05:00:00
          System.debug('myDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + myDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));

          Datetime newDateTime = myDateTime.addDays(1);

          //DEBUG|newDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-04 23:00:00
          System.debug('newDateTime.format(yyyy-MM-dd HH:mm:ss):' + newDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //|DEBUG|newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):2018-11-05 05:00:00
          System.debug('newDateTime.formatGMT(yyyy-MM-dd HH:mm:ss):' + newDateTime.formatGMT('yyyy-MM-dd HH:mm:ss'));



          Datetime myDateTime = Datetime.newInstance(2018, 11, 4);


          here you constructing local Chicago time 4-th of November 00:00:00



          after 2 hours, it is 02:00:00 and immediately time goes back 1 hour and it becomes 01:00:00 time. So you have not 24 hours per day, but 25.



          And looks like Datetime.addDays method adds 24 hours to Datetime and that is why after myDateTime.addDays(1) you have 2018-11-04 23:00:00. If you add 25 hours to it, you will get expected 2018-11-05 00:00:00 and Monday result.




          What final conclusion I did from current case.



          If you don't have to work with/get/manipulate with hours, minutes and seconds - always use Date class. Because it adds days correctly with all daylight saving time offsets.



          Date myDate = Date.newInstance(2018, 11, 4);

          //DEBUG|myDate.format(yyyy-MM-dd):11/4/2018
          System.debug('myDate.format(yyyy-MM-dd):' + myDate.format());

          Date newMyDate = myDate.addDays(1);

          //DEBUG|newMyDate.format:11/5/2018
          System.debug('newMyDate.format:' + newMyDate.format());
          DateTime newMyDateTime = DateTime.newInstance(newMyDate.year(), newMyDate.month(), newMyDate.day());

          //newMyDateTime.format(yyyy-MM-dd HH:mm:ss):2018-11-05 00:00:00
          System.debug('newMyDateTime.format(yyyy-MM-dd HH:mm:ss):' + newMyDateTime.format('yyyy-MM-dd HH:mm:ss'));

          //DEBUG|newMyDateTime.format(EEEE):Monday
          System.debug('newMyDateTime.format(EEEE):' + newMyDateTime.format('EEEE'));


          from upper snippet, we convert Date to Datetime at the latest step, where we need to know what is a day of the week. But all manipulations we did with Date class







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 11 mins ago

























          answered 2 hours ago









          Oleksandr Berehovskiy

          8,36021835




          8,36021835











          • I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
            – Prady
            2 hours ago










          • @Prady what timezone do you have on your user?
            – Oleksandr Berehovskiy
            2 hours ago










          • (GMT-06:00) Central Standard Time (America/Chicago)
            – Prady
            2 hours ago










          • @Prady I have updated my answer.
            – Oleksandr Berehovskiy
            23 mins ago
















          • I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
            – Prady
            2 hours ago










          • @Prady what timezone do you have on your user?
            – Oleksandr Berehovskiy
            2 hours ago










          • (GMT-06:00) Central Standard Time (America/Chicago)
            – Prady
            2 hours ago










          • @Prady I have updated my answer.
            – Oleksandr Berehovskiy
            23 mins ago















          I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
          – Prady
          2 hours ago




          I specifically wanted to create on users timezone because when i run the code using GMT i get 4 nov as Saturday and 5 Nov as Sunday. Actually 4th is Sunday and 5th is a Monday
          – Prady
          2 hours ago












          @Prady what timezone do you have on your user?
          – Oleksandr Berehovskiy
          2 hours ago




          @Prady what timezone do you have on your user?
          – Oleksandr Berehovskiy
          2 hours ago












          (GMT-06:00) Central Standard Time (America/Chicago)
          – Prady
          2 hours ago




          (GMT-06:00) Central Standard Time (America/Chicago)
          – Prady
          2 hours ago












          @Prady I have updated my answer.
          – Oleksandr Berehovskiy
          23 mins ago




          @Prady I have updated my answer.
          – Oleksandr Berehovskiy
          23 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f238465%2fwhy-are-both-nov-4-and-nov-5-2018-showing-as-sunday%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke