Month, Day, Year and Day of the Week

P

Philosophaie

Need to know the "Time" functions are correct:

I know
Time.Hour=Hour
Time.Minute=Minute
Time.Second=Second

I need to know the correct:
Time.???=Month
Time.???=Day
Time.???=Year
Time.???=DayOfWeek
 
R

Rick Rothstein

What programming language is that? The Excel programming language is VBA
(Visual Basic for Applications) and, in it, the Time function does not have
properties. In the VB world, there is a Month, Day, Year, Hour, Minute and
Second function that, when passed a real date value, returns the obvious
value as per the function's name. As for a DayOfWeek function, that would be
the WeekDay function in VB.
 
P

Philosophaie

Need to read the "day of the week" and when it is "Saturday" or "Sunday". In
VB.net you can use the "Now" function and divide all the parameters
"Hour,Minute...Year". I thought I could do it with the time function.
 
R

Rick Rothstein

Sorry, but I am not familiar with VB.NET. In VBA, the Now function returns
not only the current date, it also returns the current time. If Now does the
same in VB.NET, then perhaps you can reach the time values using Now.Hour,
Now.Minute, Now.Second and Now.DayOfWeek (this is only a guess on my part
though, I have no way to test it).
 
C

Chip Pearson

VBA has built-in functions for getting components of a date or time:

Dim DT As Date
Dim YYYY As Long
Dim MM As Long
Dim DD As Long
Dim DDD As String
Dim DDDD As String
Dim DOW As Long

DT = Now
YYYY = Year(DT)
MM = Month(DT)
DD = Day(DT)
DDD = Format(DT, "ddd")
DDDD = Format(DT, "dddd")
DOW = Weekday(DT)
Debug.Print DT, YYYY, MM, DD, YYYY, DDD, DDDD, DOW

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top