Why is my date of week printing one day behind today?

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
2
down vote

favorite












having some date issues. Here is my code snippet (enjoy the name of my method) >>



public class DateLogicClass 

public static void iHopeThisWorks()
//Declaring all my variables
Date startDate;
Date endDate;
Date materialsDueDate;
Date internalDueDate;
Boolean materialsDue2Weeks = True;

//System.debug('What is the date here?, nothing?' + startDate);

startDate = date.today();
endDate = date.today();
DateTime endDateDT = endDate;
String dayOfWeekString = endDateDT.format('EEEE');


System.debug('What is the date here? Thursday? ' + dayOfWeekString);

switch on dayofWeekString
when 'Monday'
System.debug('What is the date here? ' + dayOfWeekString);
materialsDueDate = startDate - 5;
System.debug('What is the date here?' + materialsDueDate);

when 'Tuesday'
System.debug('This line won't print' + dayOfWeekString);

when 'Wednesday'
when 'Thursday'
when 'Friday'
when 'Saturday'
when 'Sunday'
when null








I've put in today's date and it's Thursday 7:00P EST (I'm in Washington, DC) but when I print to the debug log, I get this:
enter image description here



Which is a full day behind. I've checked my locale settings and time settings in my org, they are set to English and Eastern time. So I'm sort of confused what I'm doing work. Any ideas?










share|improve this question



























    up vote
    2
    down vote

    favorite












    having some date issues. Here is my code snippet (enjoy the name of my method) >>



    public class DateLogicClass 

    public static void iHopeThisWorks()
    //Declaring all my variables
    Date startDate;
    Date endDate;
    Date materialsDueDate;
    Date internalDueDate;
    Boolean materialsDue2Weeks = True;

    //System.debug('What is the date here?, nothing?' + startDate);

    startDate = date.today();
    endDate = date.today();
    DateTime endDateDT = endDate;
    String dayOfWeekString = endDateDT.format('EEEE');


    System.debug('What is the date here? Thursday? ' + dayOfWeekString);

    switch on dayofWeekString
    when 'Monday'
    System.debug('What is the date here? ' + dayOfWeekString);
    materialsDueDate = startDate - 5;
    System.debug('What is the date here?' + materialsDueDate);

    when 'Tuesday'
    System.debug('This line won't print' + dayOfWeekString);

    when 'Wednesday'
    when 'Thursday'
    when 'Friday'
    when 'Saturday'
    when 'Sunday'
    when null








    I've put in today's date and it's Thursday 7:00P EST (I'm in Washington, DC) but when I print to the debug log, I get this:
    enter image description here



    Which is a full day behind. I've checked my locale settings and time settings in my org, they are set to English and Eastern time. So I'm sort of confused what I'm doing work. Any ideas?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      having some date issues. Here is my code snippet (enjoy the name of my method) >>



      public class DateLogicClass 

      public static void iHopeThisWorks()
      //Declaring all my variables
      Date startDate;
      Date endDate;
      Date materialsDueDate;
      Date internalDueDate;
      Boolean materialsDue2Weeks = True;

      //System.debug('What is the date here?, nothing?' + startDate);

      startDate = date.today();
      endDate = date.today();
      DateTime endDateDT = endDate;
      String dayOfWeekString = endDateDT.format('EEEE');


      System.debug('What is the date here? Thursday? ' + dayOfWeekString);

      switch on dayofWeekString
      when 'Monday'
      System.debug('What is the date here? ' + dayOfWeekString);
      materialsDueDate = startDate - 5;
      System.debug('What is the date here?' + materialsDueDate);

      when 'Tuesday'
      System.debug('This line won't print' + dayOfWeekString);

      when 'Wednesday'
      when 'Thursday'
      when 'Friday'
      when 'Saturday'
      when 'Sunday'
      when null








      I've put in today's date and it's Thursday 7:00P EST (I'm in Washington, DC) but when I print to the debug log, I get this:
      enter image description here



      Which is a full day behind. I've checked my locale settings and time settings in my org, they are set to English and Eastern time. So I'm sort of confused what I'm doing work. Any ideas?










      share|improve this question













      having some date issues. Here is my code snippet (enjoy the name of my method) >>



      public class DateLogicClass 

      public static void iHopeThisWorks()
      //Declaring all my variables
      Date startDate;
      Date endDate;
      Date materialsDueDate;
      Date internalDueDate;
      Boolean materialsDue2Weeks = True;

      //System.debug('What is the date here?, nothing?' + startDate);

      startDate = date.today();
      endDate = date.today();
      DateTime endDateDT = endDate;
      String dayOfWeekString = endDateDT.format('EEEE');


      System.debug('What is the date here? Thursday? ' + dayOfWeekString);

      switch on dayofWeekString
      when 'Monday'
      System.debug('What is the date here? ' + dayOfWeekString);
      materialsDueDate = startDate - 5;
      System.debug('What is the date here?' + materialsDueDate);

      when 'Tuesday'
      System.debug('This line won't print' + dayOfWeekString);

      when 'Wednesday'
      when 'Thursday'
      when 'Friday'
      when 'Saturday'
      when 'Sunday'
      when null








      I've put in today's date and it's Thursday 7:00P EST (I'm in Washington, DC) but when I print to the debug log, I get this:
      enter image description here



      Which is a full day behind. I've checked my locale settings and time settings in my org, they are set to English and Eastern time. So I'm sort of confused what I'm doing work. Any ideas?







      apex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      Cynthia

      277




      277




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Don't use type coercion, as it can have unpredictable results. Basically, these two lines are tripping you up:



          Date endDate = Date.today();
          Datetime endDateDT = endDate;


          You should instead use Datetime.newInstance with a specific Time instance:



          Datetime endTime = Datetime.newInstance(endDate, Time.newInstance(12, 0, 0, 0));





          share|improve this answer




















            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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f237333%2fwhy-is-my-date-of-week-printing-one-day-behind-today%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



            accepted










            Don't use type coercion, as it can have unpredictable results. Basically, these two lines are tripping you up:



            Date endDate = Date.today();
            Datetime endDateDT = endDate;


            You should instead use Datetime.newInstance with a specific Time instance:



            Datetime endTime = Datetime.newInstance(endDate, Time.newInstance(12, 0, 0, 0));





            share|improve this answer
























              up vote
              3
              down vote



              accepted










              Don't use type coercion, as it can have unpredictable results. Basically, these two lines are tripping you up:



              Date endDate = Date.today();
              Datetime endDateDT = endDate;


              You should instead use Datetime.newInstance with a specific Time instance:



              Datetime endTime = Datetime.newInstance(endDate, Time.newInstance(12, 0, 0, 0));





              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                Don't use type coercion, as it can have unpredictable results. Basically, these two lines are tripping you up:



                Date endDate = Date.today();
                Datetime endDateDT = endDate;


                You should instead use Datetime.newInstance with a specific Time instance:



                Datetime endTime = Datetime.newInstance(endDate, Time.newInstance(12, 0, 0, 0));





                share|improve this answer












                Don't use type coercion, as it can have unpredictable results. Basically, these two lines are tripping you up:



                Date endDate = Date.today();
                Datetime endDateDT = endDate;


                You should instead use Datetime.newInstance with a specific Time instance:



                Datetime endTime = Datetime.newInstance(endDate, Time.newInstance(12, 0, 0, 0));






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 4 hours ago









                Adrian Larson♦

                102k19108229




                102k19108229



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f237333%2fwhy-is-my-date-of-week-printing-one-day-behind-today%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery