473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
17 1530
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r =...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
7
by: daniel kaplan | last post by:
hello all, am new to HTML and am in the process of creating a form, no serious headaches, but am stumped on two types of fields. i can take care of these situations using javascript, but was...
5
by: Helen R Martin | last post by:
I'm struggling once more with the dates in one of my Access projects.. I'd like the date/time fields to be just date fields.. its just confusing the folks using the database, and its making it...
1
by: ESPNSTI | last post by:
Hi, I'd like to be able to distinguish between a DateTime variable that is allowed to hold both date and time and a DateTime variable that is allowed to only hold a Date. The reason's for this...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
3
by: colleen1980 | last post by:
Hi: Data in my table is in that format. How to i separate date with time. 11/9/2006 10:10:46 AM Thank You.
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
2
by: Andrus | last post by:
I need to display and edit only date part in DataGridView column whose data source type is DateTime?. The following code shows and allows to edit also time part. How to modify this code so that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.