Results 1 to 6 of 6

Thread: best way to handle dates

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    159

    best way to handle dates

    what's the best way to handle dates in .net and sql
    i recieve this form my sql in my app

    11/11/2005 12:00:00
    but I don't want that, what i want is to get the date not the time

    11/11/2005
    how can I fix it??

  2. #2
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    Re: best way to handle dates

    MS SQL defines no seperate date and time data types. It only provides a single Date type which stores both the date and time

    To get the current date in VB.Net you can use something like the following

    Console.WriteLine(Date.Now.Date)

    What this actually happens here is Date.Now gives you the current Date & Time and .Date removes the time portion !

    If you insert a Date.Now.Date into a SQL database it will actually be stored as Date.Now (pesudo) .Midnight

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    159

    Re: best way to handle dates

    so, If I receive 11/11/2005 12:00:00 as string from sql server
    how should I validate only date??

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: best way to handle dates

    you could use the split function to grab only the date out
    VB Code:
    1. Dim SplitDate() as String
    2. Dim NewDate as String
    3. SplitDate = Split("11/11/2005 12:00:00 AM"," ")
    4. NewDate = SplitDate(0)

    HTH

  5. #5
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: best way to handle dates

    or better yet:
    Code:
    DateTime.Parse(string).ToShortDateString()

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    159

    Resolved Re: best way to handle dates

    thx all for ur help
    I'm using Briantcva's answer..

    thx man!

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