how to get present time?

M

Mich

Hi,

i want to put the present time (hours, minutes , seconds only) in a
variable.
I tried with
dim ti as date
dim ti as datetime
dim ti as dateandtime
....
without succes
Thanks for help
Mich
 
H

Herfried K. Wagner [MVP]

Mich said:
i want to put the present time (hours, minutes , seconds only) in a
variable.
I tried with
dim ti as date
dim ti as datetime
dim ti as dateandtime

'DateTime' (a.k.a. 'Date' in VB) always has components for year, month, and
day respectively. Nevertheless, you can just take hours, minutes, and
seconds from the current date by its 'TimeOfDay' property. The current date
can be obtained using 'Now'.
 
M

Mich

Thanks

Herfried K. Wagner said:
'DateTime' (a.k.a. 'Date' in VB) always has components for year, month,
and day respectively. Nevertheless, you can just take hours, minutes, and
seconds from the current date by its 'TimeOfDay' property. The current
date can be obtained using 'Now'.
 
G

Guest

Dim theTimeNow As Date = Date.Now

Dim theYear As String = Format(CShort(DateAndTime.Year(theTimeNow)), "0000")
Dim theMonth As String = Format(CShort(DateAndTime.Month(theTimeNow)), "00")
Dim theDay As String = Format(CShort(DateAndTime.Day(theTimeNow)), "00")

Dim theHour As String = Format(CShort(DateAndTime.Hour(theTimeNow)), "00")
Dim theMinute As String = Format(CShort(DateAndTime.Minute(theTimeNow)), "00")
Dim theSec As String = Format(CShort(DateAndTime.Second(theTimeNow)), "00")

Dim tempString As String = theYear & "_" & _
theMonth & "_" & _
theDay & "_" & _
theHour & "-" & _
theMinute & "-" & _
theSec
 
A

Armin Zingler

chad said:
Dim theTimeNow As Date = Date.Now

Dim theYear As String = Format(CShort(DateAndTime.Year(theTimeNow)),
"0000")
Dim theMonth As String =
Format(CShort(DateAndTime.Month(theTimeNow)), "00")
Dim theDay As
String = Format(CShort(DateAndTime.Day(theTimeNow)), "00")

Dim theHour As String = Format(CShort(DateAndTime.Hour(theTimeNow)),
"00")
Dim theMinute As String =
Format(CShort(DateAndTime.Minute(theTimeNow)), "00")
Dim theSec As
String = Format(CShort(DateAndTime.Second(theTimeNow)), "00")

Dim tempString As String = theYear & "_" & _
theMonth & "_" & _
theDay & "_" & _
theHour & "-" & _
theMinute & "-" & _
theSec


Or

tempString = Date.Now.ToString("yyyy_MM_dd_HH_mm_ss")


Armin
 

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