467,146 Members | 1,305 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

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 LastWorkDayOfTheMonth(ByVal dtmdate As Date) As Date

Dim x As Date = LastDayOfTheMonthDate(dtmdate)

Do While IsWeekday(x) = False

x = x.AddDays(-1)

Loop

Return x.Date

End Function
Jun 27 '08 #1
  • viewed: 1366
Share:
17 Replies
"Brian S." <bs********@community.nospamschrieb
Hi,
why does this function return the date and time.. I only want the
date to return.. no time on it :(
Public Shared Function LastWorkDayOfTheMonth(ByVal dtmdate As Date)
As Date

Dim x As Date = LastDayOfTheMonthDate(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
Jun 27 '08 #2
Then return it as string
Return x.Date.ToString("dd-MM-yyyy")


Jun 27 '08 #3
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*******@freenet.dewrote in message
news:O%****************@TK2MSFTNGP05.phx.gbl...
"Brian S." <bs********@community.nospamschrieb
>Hi,
why does this function return the date and time.. I only want the
date to return.. no time on it :(
Public Shared Function LastWorkDayOfTheMonth(ByVal dtmdate As Date)
As Date

Dim x As Date = LastDayOfTheMonthDate(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

Jun 27 '08 #4
"Brian S." <bs********@community.nospamwrote in message
news:%2****************@TK2MSFTNGP03.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*******@freenet.dewrote in message
news:O%****************@TK2MSFTNGP05.phx.gbl...
>"Brian S." <bs********@community.nospamschrieb
>>Hi,
why does this function return the date and time.. I only want the
date to return.. no time on it :(
Public Shared Function LastWorkDayOfTheMonth(ByVal dtmdate As Date)
As Date

Dim x As Date = LastDayOfTheMonthDate(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.
Jun 27 '08 #5
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

Jun 27 '08 #6
"Brian S." <bs********@community.nospamschrieb
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

Jun 27 '08 #7
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*******@freenet.dewrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
"Brian S." <bs********@community.nospamschrieb
>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

Jun 27 '08 #8
Ok, I think i do understand now.. somewhat....
I was calling this function by
Me.txtLastWorkDay.Text =
clsDateFunctions.LastWorkDayOfTheMonth(Me.MonthCal endar1.SelectionStart.Date)

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

when I do this

Me.txtLastWorkDay.Text =
CStr(clsDateFunctions.LastWorkDayOfTheMonth(Me.Mon thCalendar1.SelectionStart.Date))

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

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
"Brian S." <bs********@community.nospamschrieb
>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

Jun 27 '08 #9
Brian S. wrote:
Ok, I think i do understand now.. somewhat....
I was calling this function by
Me.txtLastWorkDay.Text =
clsDateFunctions.LastWorkDayOfTheMonth(Me.MonthCal endar1.SelectionStart.Date)

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

when I do this

Me.txtLastWorkDay.Text =
CStr(clsDateFunctions.LastWorkDayOfTheMonth(Me.Mon thCalendar1.SelectionStart.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 = clsDateFunctions.LastWorkDayOfTheMonth( _
Me.MonthCalendar1.SelectionStart.Date)
Me.txtLastWorkDay.Text = NewDate.ToString("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.txtLastWorkDay.Text = NewDate.ToShortDateString

You are the programmer, so take control of the situation. :)
Jun 27 '08 #10
"Brian S." <bs********@community.nospamschrieb
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

Jun 27 '08 #11
Armin,

The literal is only made for the US customers.

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:ep*************@TK2MSFTNGP05.phx.gbl...
"Brian S." <bs********@community.nospamschrieb
>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
Jun 27 '08 #12
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
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

Jun 27 '08 #13
"Brian S." <bs********@community.nospamschrieb
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.txtLastWorkDay.Text =
clsDateFunctions.LastWorkDayOfTheMonth(Me.MonthCal endar1.SelectionStart.Date)

What's the type of the return value of LastWorkDayOfTheMonth? It's Date,
taken from your other post.
What's the type of Me.txtLastWorkDay.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

Jun 27 '08 #14
not sure i can explain it :(.. I just know, and checked again that Option
Strict is turned on.

"Armin Zingler" <az*******@freenet.dewrote in message
news:OM**************@TK2MSFTNGP03.phx.gbl...
"Brian S." <bs********@community.nospamschrieb
>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.txtLastWorkDay.Text =
clsDateFunctions.LastWorkDayOfTheMonth(Me.MonthCal endar1.SelectionStart.Date)

What's the type of the return value of LastWorkDayOfTheMonth? It's Date,
taken from your other post.
What's the type of Me.txtLastWorkDay.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

Jun 27 '08 #15
Armin,

The representation of a Date in MM-dd-yyyy is solely in the US culture

Everywhere else on the world this is not an (official) date representation
but just some characters in a string

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:Oa**************@TK2MSFTNGP03.phx.gbl...
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
>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
Jun 27 '08 #16
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
Armin,

The representation of a Date in MM-dd-yyyy is solely in the US
culture

Everywhere else on the world this is not an (official) date
representation but just some characters in a string
Yes, I know. We know. :-) What I meant: You wrote "The *literal* is
only made for the US customers.", but the literal is always
#mm/dd/yyyy#, no matter in which country/culture (setting).
Armin

Jun 27 '08 #17
Armin,

I knew too that we know.

:-)

Cor

"Armin Zingler" <az*******@freenet.deschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
>Armin,

The representation of a Date in MM-dd-yyyy is solely in the US
culture

Everywhere else on the world this is not an (official) date
representation but just some characters in a string

Yes, I know. We know. :-) What I meant: You wrote "The *literal* is only
made for the US customers.", but the literal is always #mm/dd/yyyy#, no
matter in which country/culture (setting).
Armin
Jun 27 '08 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by androtech | last post: by
7 posts views Thread by Marc Pelletier | last post: by
30 posts views Thread by Dr John Stockton | last post: by
7 posts views Thread by daniel kaplan | last post: by
5 posts views Thread by Helen R Martin | last post: by
1 post views Thread by ESPNSTI | last post: by
3 posts views Thread by colleen1980@gmail.com | last post: by
2 posts views Thread by Andrus | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.