Adding days to the Date portion of DateTime throws off the Time portionCalculate days between DateTime field...

The need of reserving one's ability in job interviews

A right or the right?

If nine coins are tossed, what is the probability that the number of heads is even?

Second-rate spelling

Book about a time-travel war fought by computers

Erro: incompatible type for argument 1 of 'printf'

Is it possible to convert a suspension fork to rigid by drilling it?

What am I? I am in theaters and computer programs

Achieving MPPT of a solar panel with LM2596

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Rationale to prefer local variables over instance variables?

Citing contemporaneous (interlaced?) preprints

When was drinking water recognized as crucial in marathon running?

Non-Italian European mafias in USA?

Is there a full canon version of Tyrion's jackass/honeycomb joke?

In Adventurer's League, is it possible to keep the Ring of Winter if you manage to acquire it in the Tomb of Annihilation adventure?

Is divide-by-zero a security vulnerability?

Does an unattuned Frost Brand weapon still glow in freezing temperatures?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

Skis versus snow shoes - when to choose which for travelling the backcountry?

Adding days to the Date portion of DateTime throws off the Time portion

Where is the fallacy here?

Does Garmin Oregon 700 have Strava integration?

Can a space-faring robot still function over a billion years?



Adding days to the Date portion of DateTime throws off the Time portion


Calculate days between DateTime field and Now()Combine Date from one datetime field with Time from anotherAdding a time to datetimedifference between two date time fields in daysConvert String DateTime to User Locale Date TimeNew Datetime instance on Daylight Savings Time transition date?Time portion of Datetime formula field inconsistentParse date time string to Apex DateTimeConsume Date/time Iso 8601 timestamp in salesforce Datetime fieldAdding days and then business days to a datetime field













2















So I'm having an issue in Apex with the Date's addDays function. It seems that adding more than a certain amount of days throws off the time by one hour. It all seems so arbitrary so I'm wondering if this is a known thing in Salesforce or not.



DateTime aDate = System.now();
System.debug(aDate);
DateTime adjustedDate =
DateTime.newInstance(aDate.date().addDays(4), aDate.time());


System.debug(adjustedDate);



Running that in an execute anonymous box outputs the following:
2019-03-05 17:44:28
2019-03-09 17:44:28



That's all good. The same date separated by four days and the same time. Just as you'd expect. But... adding five or more days causes behavior I can't wrap my head around.



DateTime aDate = System.now();
System.debug(aDate);
DateTime adjustedDate =
DateTime.newInstance(aDate.date().addDays(5), aDate.time());
System.debug(adjustedDate);


This outputs the following:
2019-03-05 17:46:08
2019-03-10 16:46:08



It falls back by an hour. Any idea why or is this a known thing? I'm in central timezone so my time is actually -6 hours from the printed time.










share|improve this question







New contributor




Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    2















    So I'm having an issue in Apex with the Date's addDays function. It seems that adding more than a certain amount of days throws off the time by one hour. It all seems so arbitrary so I'm wondering if this is a known thing in Salesforce or not.



    DateTime aDate = System.now();
    System.debug(aDate);
    DateTime adjustedDate =
    DateTime.newInstance(aDate.date().addDays(4), aDate.time());


    System.debug(adjustedDate);



    Running that in an execute anonymous box outputs the following:
    2019-03-05 17:44:28
    2019-03-09 17:44:28



    That's all good. The same date separated by four days and the same time. Just as you'd expect. But... adding five or more days causes behavior I can't wrap my head around.



    DateTime aDate = System.now();
    System.debug(aDate);
    DateTime adjustedDate =
    DateTime.newInstance(aDate.date().addDays(5), aDate.time());
    System.debug(adjustedDate);


    This outputs the following:
    2019-03-05 17:46:08
    2019-03-10 16:46:08



    It falls back by an hour. Any idea why or is this a known thing? I'm in central timezone so my time is actually -6 hours from the printed time.










    share|improve this question







    New contributor




    Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      2












      2








      2








      So I'm having an issue in Apex with the Date's addDays function. It seems that adding more than a certain amount of days throws off the time by one hour. It all seems so arbitrary so I'm wondering if this is a known thing in Salesforce or not.



      DateTime aDate = System.now();
      System.debug(aDate);
      DateTime adjustedDate =
      DateTime.newInstance(aDate.date().addDays(4), aDate.time());


      System.debug(adjustedDate);



      Running that in an execute anonymous box outputs the following:
      2019-03-05 17:44:28
      2019-03-09 17:44:28



      That's all good. The same date separated by four days and the same time. Just as you'd expect. But... adding five or more days causes behavior I can't wrap my head around.



      DateTime aDate = System.now();
      System.debug(aDate);
      DateTime adjustedDate =
      DateTime.newInstance(aDate.date().addDays(5), aDate.time());
      System.debug(adjustedDate);


      This outputs the following:
      2019-03-05 17:46:08
      2019-03-10 16:46:08



      It falls back by an hour. Any idea why or is this a known thing? I'm in central timezone so my time is actually -6 hours from the printed time.










      share|improve this question







      New contributor




      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      So I'm having an issue in Apex with the Date's addDays function. It seems that adding more than a certain amount of days throws off the time by one hour. It all seems so arbitrary so I'm wondering if this is a known thing in Salesforce or not.



      DateTime aDate = System.now();
      System.debug(aDate);
      DateTime adjustedDate =
      DateTime.newInstance(aDate.date().addDays(4), aDate.time());


      System.debug(adjustedDate);



      Running that in an execute anonymous box outputs the following:
      2019-03-05 17:44:28
      2019-03-09 17:44:28



      That's all good. The same date separated by four days and the same time. Just as you'd expect. But... adding five or more days causes behavior I can't wrap my head around.



      DateTime aDate = System.now();
      System.debug(aDate);
      DateTime adjustedDate =
      DateTime.newInstance(aDate.date().addDays(5), aDate.time());
      System.debug(adjustedDate);


      This outputs the following:
      2019-03-05 17:46:08
      2019-03-10 16:46:08



      It falls back by an hour. Any idea why or is this a known thing? I'm in central timezone so my time is actually -6 hours from the printed time.







      apex datetime bug






      share|improve this question







      New contributor




      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 hours ago









      DylanDylan

      132




      132




      New contributor




      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Daylight saving time 2019 in central timezone will begin at



          2:00 AM on
          Sunday, March 10



          and ends at



          2:00 AM on
          Sunday, November 3



          All times are in Central Time.



          :)






          share|improve this answer
























          • In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

            – Derek F
            3 hours ago











          • Wow. I completely forgot about Daylight savings time. Thank you!

            – Dylan
            3 hours ago











          • +1. Great observation on Daylight changes.

            – Jayant Das
            1 hour 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',
          autoActivateHeartbeat: false,
          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
          });


          }
          });






          Dylan is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f252620%2fadding-days-to-the-date-portion-of-datetime-throws-off-the-time-portion%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Daylight saving time 2019 in central timezone will begin at



          2:00 AM on
          Sunday, March 10



          and ends at



          2:00 AM on
          Sunday, November 3



          All times are in Central Time.



          :)






          share|improve this answer
























          • In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

            – Derek F
            3 hours ago











          • Wow. I completely forgot about Daylight savings time. Thank you!

            – Dylan
            3 hours ago











          • +1. Great observation on Daylight changes.

            – Jayant Das
            1 hour ago
















          3














          Daylight saving time 2019 in central timezone will begin at



          2:00 AM on
          Sunday, March 10



          and ends at



          2:00 AM on
          Sunday, November 3



          All times are in Central Time.



          :)






          share|improve this answer
























          • In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

            – Derek F
            3 hours ago











          • Wow. I completely forgot about Daylight savings time. Thank you!

            – Dylan
            3 hours ago











          • +1. Great observation on Daylight changes.

            – Jayant Das
            1 hour ago














          3












          3








          3







          Daylight saving time 2019 in central timezone will begin at



          2:00 AM on
          Sunday, March 10



          and ends at



          2:00 AM on
          Sunday, November 3



          All times are in Central Time.



          :)






          share|improve this answer













          Daylight saving time 2019 in central timezone will begin at



          2:00 AM on
          Sunday, March 10



          and ends at



          2:00 AM on
          Sunday, November 3



          All times are in Central Time.



          :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Aayush KAayush K

          1,10247




          1,10247













          • In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

            – Derek F
            3 hours ago











          • Wow. I completely forgot about Daylight savings time. Thank you!

            – Dylan
            3 hours ago











          • +1. Great observation on Daylight changes.

            – Jayant Das
            1 hour ago



















          • In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

            – Derek F
            3 hours ago











          • Wow. I completely forgot about Daylight savings time. Thank you!

            – Dylan
            3 hours ago











          • +1. Great observation on Daylight changes.

            – Jayant Das
            1 hour ago

















          In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

          – Derek F
          3 hours ago





          In other words, Daylight Saving Time begins in 5 days at this point in time. Which explains the discrepancy between adding 4 days and 5 days.

          – Derek F
          3 hours ago













          Wow. I completely forgot about Daylight savings time. Thank you!

          – Dylan
          3 hours ago





          Wow. I completely forgot about Daylight savings time. Thank you!

          – Dylan
          3 hours ago













          +1. Great observation on Daylight changes.

          – Jayant Das
          1 hour ago





          +1. Great observation on Daylight changes.

          – Jayant Das
          1 hour ago










          Dylan is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Dylan is a new contributor. Be nice, and check out our Code of Conduct.













          Dylan is a new contributor. Be nice, and check out our Code of Conduct.












          Dylan is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Salesforce Stack Exchange!


          • 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%2fsalesforce.stackexchange.com%2fquestions%2f252620%2fadding-days-to-the-date-portion-of-datetime-throws-off-the-time-portion%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

          As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

          Список ссавців Італії Природоохоронні статуси | Список |...

          Українські прізвища Зміст Історичні відомості |...