date only

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian S.

    #1

    date only

    Hi,
    why does this function return the date and time.. I only want the date to
    return.. no time on it :(
    Public Shared Function LastWorkDayOfTh eMonth(ByVal dtmdate As Date) As Date



    Dim x As Date = LastDayOfTheMon thDate(dtmdate)

    Do While IsWeekday(x) = False

    x = x.AddDays(-1)

    Loop

    Return x.Date

    End Function


  • Armin Zingler

    #2
    Re: date only

    "Brian S." <bsgallatin@com munity.nospamsc hrieb
    Hi,
    why does this function return the date and time.. I only want the
    date to return.. no time on it :(
    Public Shared Function LastWorkDayOfTh eMonth(ByVal dtmdate As Date)
    As Date
    >
    >
    >
    Dim x As Date = LastDayOfTheMon thDate(dtmdate)
    >
    Do While IsWeekday(x) = False
    >
    x = x.AddDays(-1)
    >
    Loop
    >
    Return x.Date
    >
    End Function
    What do you pass to the function? Where does the value come from?


    Armin

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: date only

      Then return it as string


      Return x.Date.ToString ("dd-MM-yyyy")




      Comment

      • Brian S.

        #4
        Re: date only

        I pass it a date.....
        #4/1/08#.. when I follow through the code all the way to the Return x.Date,
        it still has the #4/31/08# format, but in the textbox it includes 12:00

        "Armin Zingler" <az.nospam@free net.dewrote in message
        news:O%23ecTHHo IHA.2256@TK2MSF TNGP05.phx.gbl. ..
        "Brian S." <bsgallatin@com munity.nospamsc hrieb
        >Hi,
        >why does this function return the date and time.. I only want the
        >date to return.. no time on it :(
        >Public Shared Function LastWorkDayOfTh eMonth(ByVal dtmdate As Date)
        >As Date
        >>
        >>
        >>
        >Dim x As Date = LastDayOfTheMon thDate(dtmdate)
        >>
        >Do While IsWeekday(x) = False
        >>
        >x = x.AddDays(-1)
        >>
        >Loop
        >>
        >Return x.Date
        >>
        >End Function
        >
        What do you pass to the function? Where does the value come from?
        >
        >
        Armin

        Comment

        • Michael D. Ober

          #5
          Re: date only

          "Brian S." <bsgallatin@com munity.nospamwr ote in message
          news:%23A98G$Ho IHA.4912@TK2MSF TNGP03.phx.gbl. ..
          >I pass it a date.....
          #4/1/08#.. when I follow through the code all the way to the Return
          x.Date, it still has the #4/31/08# format, but in the textbox it includes
          12:00
          >
          "Armin Zingler" <az.nospam@free net.dewrote in message
          news:O%23ecTHHo IHA.2256@TK2MSF TNGP05.phx.gbl. ..
          >"Brian S." <bsgallatin@com munity.nospamsc hrieb
          >>Hi,
          >>why does this function return the date and time.. I only want the
          >>date to return.. no time on it :(
          >>Public Shared Function LastWorkDayOfTh eMonth(ByVal dtmdate As Date)
          >>As Date
          >>>
          >>>
          >>>
          >>Dim x As Date = LastDayOfTheMon thDate(dtmdate)
          >>>
          >>Do While IsWeekday(x) = False
          >>>
          >>x = x.AddDays(-1)
          >>>
          >>Loop
          >>>
          >>Return x.Date
          >>>
          >>End Function
          >>
          >What do you pass to the function? Where does the value come from?
          >>
          >>
          >Armin
          Your function is working correctly. The problem is that your textbox display
          isn't. A datetime value that has been truncated to just the date will show
          12:00 AM for the time. Change your textbox to only show the part of the
          date you want.

          Mike.


          Comment

          • Rory Becker

            #6
            Re: date only

            Hello Brian S.,
            I pass it a date.....
            #4/1/08#.. when I follow through the code all the way to the Return
            x.Date,
            it still has the #4/31/08# format, but in the textbox it includes
            12:00
            The VB DataType "Date" maps to the Framework "DateTime" DataType.

            Therefore it will always contain a time component.

            If you subtract the time in question from the date in question, you will
            internally be storing 00:00:00 (midnight) on the date in question. depending
            on localisation this might be displayed as "00:00:00" or "12:00:00" on the
            given date.

            This leads to various issues when comparing dates.

            You might think is sensible to say...
            -------------------------------------------------------------
            If SomeDate = #20/Apr/2008# Then

            End if
            -------------------------------------------------------------
            ....when what you might really mean is...
            -------------------------------------------------------------
            If SomeDate >= #20/Apr/2008 00:00:00# andalso SomeDate < #21/Apr/2008 00:00:00
            Then

            Endif
            -------------------------------------------------------------
            ....or perhaps if you prefer...
            -------------------------------------------------------------
            If SomeDate >= #20/Apr/2008 00:00:00# andalso SomeDate <= #20/Apr/2008 23:59:59
            Then

            Endif
            -------------------------------------------------------------

            I hope this helps.

            --
            Rory



            Comment

            • Armin Zingler

              #7
              Re: date only

              "Brian S." <bsgallatin@com munity.nospamsc hrieb
              I pass it a date.....
              #4/1/08#.. when I follow through the code all the way to the Return
              x.Date, it still has the #4/31/08# format, but in the textbox it
              includes 12:00
              A DateTime object represents a certain point in time. #4/31/08 12:00AM#
              is one of these. Just like #4/31/08 15:00PM# is. If you want to display
              a DateTime object, you don't have to display the time part.

              If you have a double value 4.000 you can also not say that the value
              "contains" decimal places. It's just the way the value is displayed. You
              can omit them and display 4 only.


              Armin

              Comment

              • Brian S.

                #8
                Re: date only

                I understand about the time protion of a date type .... my problem is ..
                when you put a break point in the Return x.Date
                and in the immed window you do a ?x.date and it returns just #3/1/2008#
                That is the part i am trying to understand, why is it displayed differently
                there than it is in the text box

                "Armin Zingler" <az.nospam@free net.dewrote in message
                news:%23HhWpIJo IHA.548@TK2MSFT NGP06.phx.gbl.. .
                "Brian S." <bsgallatin@com munity.nospamsc hrieb
                >I pass it a date.....
                >#4/1/08#.. when I follow through the code all the way to the Return
                >x.Date, it still has the #4/31/08# format, but in the textbox it
                >includes 12:00
                >
                A DateTime object represents a certain point in time. #4/31/08 12:00AM# is
                one of these. Just like #4/31/08 15:00PM# is. If you want to display a
                DateTime object, you don't have to display the time part.
                >
                If you have a double value 4.000 you can also not say that the value
                "contains" decimal places. It's just the way the value is displayed. You
                can omit them and display 4 only.
                >
                >
                Armin
                >

                Comment

                • Brian S.

                  #9
                  Re: date only

                  Ok, I think i do understand now.. somewhat....
                  I was calling this function by
                  Me.txtLastWorkD ay.Text =
                  clsDateFunction s.LastWorkDayOf TheMonth(Me.Mon thCalendar1.Sel ectionStart.Dat e)

                  and that would produce the #4/30/2008 12:00#

                  when I do this

                  Me.txtLastWorkD ay.Text =
                  CStr(clsDateFun ctions.LastWork DayOfTheMonth(M e.MonthCalendar 1.SelectionStar t.Date))

                  it shows it the way I want it to...



                  "Armin Zingler" <az.nospam@free net.dewrote in message
                  news:%23HhWpIJo IHA.548@TK2MSFT NGP06.phx.gbl.. .
                  "Brian S." <bsgallatin@com munity.nospamsc hrieb
                  >I pass it a date.....
                  >#4/1/08#.. when I follow through the code all the way to the Return
                  >x.Date, it still has the #4/31/08# format, but in the textbox it
                  >includes 12:00
                  >
                  A DateTime object represents a certain point in time. #4/31/08 12:00AM# is
                  one of these. Just like #4/31/08 15:00PM# is. If you want to display a
                  DateTime object, you don't have to display the time part.
                  >
                  If you have a double value 4.000 you can also not say that the value
                  "contains" decimal places. It's just the way the value is displayed. You
                  can omit them and display 4 only.
                  >
                  >
                  Armin
                  >

                  Comment

                  • Steve Gerrard

                    #10
                    Re: date only

                    Brian S. wrote:
                    Ok, I think i do understand now.. somewhat....
                    I was calling this function by
                    Me.txtLastWorkD ay.Text =
                    clsDateFunction s.LastWorkDayOf TheMonth(Me.Mon thCalendar1.Sel ectionStart.Dat e)
                    >
                    and that would produce the #4/30/2008 12:00#
                    >
                    when I do this
                    >
                    Me.txtLastWorkD ay.Text =
                    CStr(clsDateFun ctions.LastWork DayOfTheMonth(M e.MonthCalendar 1.SelectionStar t.Date))
                    >
                    it shows it the way I want it to...
                    >
                    >
                    As you have seen, Dates do not have a single format. They are stored as a
                    numeric value, and formatted as strings on demand. While you can choose to rely
                    on something like CStr to format a date, you may want to take direct control of
                    how your dates are being displayed. For instance, you could do

                    Dim NewDate As Date
                    NewDate = clsDateFunction s.LastWorkDayOf TheMonth( _
                    Me.MonthCalenda r1.SelectionSta rt.Date)
                    Me.txtLastWorkD ay.Text = NewDate.ToStrin g("M/d/yyyy")

                    In some cases, you may want to use a standard date format, so that it reflects
                    the user's location settings. For instance, you could use
                    Me.txtLastWorkD ay.Text = NewDate.ToShort DateString

                    You are the programmer, so take control of the situation. :)


                    Comment

                    • Armin Zingler

                      #11
                      Re: date only

                      "Brian S." <bsgallatin@com munity.nospamsc hrieb
                      I understand about the time protion of a date type .... my problem
                      is .. when you put a break point in the Return x.Date
                      and in the immed window you do a ?x.date and it returns just
                      #3/1/2008# That is the part i am trying to understand, why is it
                      displayed differently there than it is in the text box
                      Because you show it in the Textbox differently from how the IDE does it
                      in the immediate window. Maybe it's shown that way because #3/1/2008# is
                      the format used with date
                      literals. (dim var as date = #3/1/2008#) That's a language/culture
                      independet format just like the whole source code that must be
                      compilable no matter in which country you open the project. I also write
                      "If", not "Wenn" (German transl.) even if i don't have an English
                      version. :-)


                      Armin

                      Comment

                      • Cor Ligthert[MVP]

                        #12
                        Re: date only

                        Armin,

                        The literal is only made for the US customers.

                        Cor

                        "Armin Zingler" <az.nospam@free net.deschreef in bericht
                        news:epr6z4JoIH A.264@TK2MSFTNG P05.phx.gbl...
                        "Brian S." <bsgallatin@com munity.nospamsc hrieb
                        >I understand about the time protion of a date type .... my problem
                        >is .. when you put a break point in the Return x.Date
                        >and in the immed window you do a ?x.date and it returns just
                        >#3/1/2008# That is the part i am trying to understand, why is it
                        >displayed differently there than it is in the text box
                        >
                        Because you show it in the Textbox differently from how the IDE does it
                        in the immediate window. Maybe it's shown that way because #3/1/2008# is
                        the format used with date
                        literals. (dim var as date = #3/1/2008#) That's a language/culture
                        independet format just like the whole source code that must be compilable
                        no matter in which country you open the project. I also write "If", not
                        "Wenn" (German transl.) even if i don't have an English version. :-)
                        >
                        >
                        Armin
                        >

                        Comment

                        • Armin Zingler

                          #13
                          Re: date only

                          "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschri eb
                          Armin,
                          >
                          The literal is only made for the US customers.
                          Sorry I don't understand. The literal is the same for everyone.

                          But I was wrong because I mixed up "?x.date" in the immediate window
                          with hovering over the DateTime variable and have the value displayed in
                          the tooltip. In the tooltip, the literal format is used.


                          Armin

                          Comment

                          • Armin Zingler

                            #14
                            Re: date only

                            "Brian S." <bsgallatin@com munity.nospamsc hrieb
                            maybe you shouldn't assume things(again).. . Option Strict On is the
                            way my enviroment is set up.
                            This line indicates that it is not turned on:

                            Me.txtLastWorkD ay.Text =
                            clsDateFunction s.LastWorkDayOf TheMonth(Me.Mon thCalendar1.Sel ectionStart.Dat e)

                            What's the type of the return value of LastWorkDayOfTh eMonth? It's Date,
                            taken from your other post.
                            What's the type of Me.txtLastWorkD ay.Text? I guess it's string. Isn't
                            it?

                            Conclusion: If you can assign one to the other, then Option Strict is
                            turned OFF. But maybe I'm overlooking something that you could please
                            kindly explain. Thanks.



                            Armin

                            Comment

                            • Brian S.

                              #15
                              Re: date only

                              not sure i can explain it :(.. I just know, and checked again that Option
                              Strict is turned on.

                              "Armin Zingler" <az.nospam@free net.dewrote in message
                              news:OMjSFRLoIH A.1772@TK2MSFTN GP03.phx.gbl...
                              "Brian S." <bsgallatin@com munity.nospamsc hrieb
                              >maybe you shouldn't assume things(again).. . Option Strict On is the
                              >way my enviroment is set up.
                              >
                              This line indicates that it is not turned on:
                              >
                              Me.txtLastWorkD ay.Text =
                              clsDateFunction s.LastWorkDayOf TheMonth(Me.Mon thCalendar1.Sel ectionStart.Dat e)
                              >
                              What's the type of the return value of LastWorkDayOfTh eMonth? It's Date,
                              taken from your other post.
                              What's the type of Me.txtLastWorkD ay.Text? I guess it's string. Isn't
                              it?
                              >
                              Conclusion: If you can assign one to the other, then Option Strict is
                              turned OFF. But maybe I'm overlooking something that you could please
                              kindly explain. Thanks.
                              >
                              >
                              >
                              Armin
                              >

                              Comment

                              Working...