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??
Printable View
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??
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
so, If I receive 11/11/2005 12:00:00 as string from sql server
how should I validate only date??
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
or better yet:
Code:DateTime.Parse(string).ToShortDateString()
thx all for ur help
I'm using Briantcva's answer..
thx man!