how to get present time?

  • Thread starter Thread starter Mich
  • Start date Start date
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
 
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'.
 
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'.
 
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
 
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
 
Back
Top