|
-
Jul 27th, 2004, 04:28 AM
#1
Thread Starter
Member
current date
hi,
how do i retrieve the current date and put it into a string ?
thx
-
Jul 27th, 2004, 04:40 AM
#2
VB Code:
Dim strDate as String = Date.Now.ToString()
This is a very basic question, and I would advise you to get a book on programming with vb.net. It would be much faster for you to learn then asking many questions (this is what usually happens). Most people are very willing to help, but a person should at least try to solve issues themselves. Its not just about getting something done, but how you got there that makes the difference between a coder and a script kiddie .
-
Jul 27th, 2004, 05:15 AM
#3
I don't live here any more.
-
Jul 27th, 2004, 09:34 AM
#4
PowerPoster
Hi Grimfort,
Is there any advantage between
Dim strDate As String = CStr(Date.Now)
and
Dim strDate as String = Date.Now.ToString() ??
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 27th, 2004, 10:44 AM
#5
With regards to this particular example, theres no reason to choose one above the other. Cstr returns a short date, and .ToString also does, but in other cases this is not always true. I spose its what I am used to doing.
Try a CStr on an enum and it returns the value, where as a ToString returns the actual enum name, for example.
A positive thing for a date.ToString, is that you can pass it the format you wish to use, or call other methods like .ToLongDateString or ToLongTimeString.
The CStr/Clng/CInt are called in-line so dont need to call a sub function to convert it, I would assume this makes it faster, but the documentation does not explicitly say this.
-
Jul 27th, 2004, 06:23 PM
#6
PowerPoster
Hi Grimfort,
Many thanks.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 27th, 2004, 08:17 PM
#7
Frenzied Member
actually, as basic as that question is, it really can be thought of as a good pointer to what the ToString() method does.
FYI, you can take practically any primitive data type or object and use ToString() to get the string representation of that value, name, etc. I say practically cause it doesn't work on all objects.
If you use Option Strict, ToString() can be your best friend if you have a lot of text to work with. 
just my .02
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|