Results 1 to 7 of 7

Thread: current date

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2004
    Posts
    34

    current date

    hi,

    how do i retrieve the current date and put it into a string ?

    thx

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    VB Code:
    1. 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 .

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I agree.
    I don't live here any more.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    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.

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  7. #7
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    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
  •  



Click Here to Expand Forum to Full Width