473,394 Members | 1,752 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,394 software developers and data experts.

how to get present time?

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
Nov 14 '07 #1
4 1414
"Mich" <sd**@qsd.qsdschrieb:
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 S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 14 '07 #2
Thanks

"Herfried K. Wagner [MVP]" <hi***************@gmx.atschreef in bericht
news:Oz***************@TK2MSFTNGP06.phx.gbl...
"Mich" <sd**@qsd.qsdschrieb:
>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 S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 14 '07 #3
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


"Mich" wrote:
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
Nov 16 '07 #4
"chad" <ch**@discussions.microsoft.comschrieb
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
Nov 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: paypal | last post by:
For those of you in the San Francisco Bay Area ... PHP5 & Web Services, The Present and the Future: Andi Gutmans of Zend, will give an overview of the PHP phenomena and how it has come to...
0
by: Kasp | last post by:
Hi there, I am trying to make an OLAP cube on a table having two columns (datetime, Number_of_times_an_event_occured). My dimension is time and I want to measure the Min and Max times an event...
5
by: Ralf Wahner | last post by:
Dear Masters of XML As I'm new to XML Schema I dare to ask a possibly recurring question: Given an element <elem> with two attributes @a and @b. The attributes are bound by the condition, that...
0
by: libreria ledi international bookseller | last post by:
BIBLIOTECA DIGITALE THE ITALIAN EBOOK PLATFORM FOR LIBRARIES Libraries’ users ask for more and more accessible information and for even more complete and updated catalogues. The Italian...
2
by: kma | last post by:
I am designing an Access 2000 database on a computer running Windows 98. I have one form with several tabs; all of which have sub forms, some with a subform on a subform. For example, on my...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
10
by: vin2sara | last post by:
Hi, Can anyone send a query to get present date and time ??I used dateformat method ,but i am not getting that.please its very urgent to me... Thank You
6
by: dlesandrini | last post by:
Hi, this is Danny Lesandrini. Been a while since I was a regular contributor to this forum, but my name still shows up from time to time. Today, I've got what might seem like an odd request: ...
9
by: csharpula csharp | last post by:
Hello, I would like to know how can I present updating (on the fly) data in a DataGrid type control. The control will get url as an input and need to present the log changing content in a DataGrid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.