|
-
Aug 18th, 2005, 08:57 AM
#1
Thread Starter
Addicted Member
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??
-
Aug 18th, 2005, 09:17 AM
#2
Hyperactive Member
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
-
Aug 18th, 2005, 10:04 AM
#3
Thread Starter
Addicted Member
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??
-
Aug 18th, 2005, 10:06 AM
#4
Re: best way to handle dates
you could use the split function to grab only the date out
VB Code:
Dim SplitDate() as String
Dim NewDate as String
SplitDate = Split("11/11/2005 12:00:00 AM"," ")
NewDate = SplitDate(0)
HTH
-
Aug 18th, 2005, 10:10 AM
#5
Fanatic Member
Re: best way to handle dates
or better yet:
Code:
DateTime.Parse(string).ToShortDateString()
-
Aug 18th, 2005, 10:28 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|