|
-
Feb 6th, 2007, 10:32 PM
#1
Thread Starter
Fanatic Member
date time error
hi,
i am retreving date from database and dispalying in datetimepicker.
while doing this i am getting error as: "String was not recognized as a valid DateTime"
how to rectify this error:
this is my code:
msgbox(ds.Tables(0).Rows(0)("expiry_date"))
i am getting 17/01/2008 as result
HRUser_dtp_expdate.Text = ds.Tables(0).Rows(0)("expiry_date")
so please help me to rectify this error
-
Feb 6th, 2007, 10:43 PM
#2
Re: date time error
Don't store dates in a database as text. Store them as dates. That way there's no possible way that an issue can occur. Would you store numbers in text fields? No you wouldn't, so what reason is there to store dates in text fields?
-
Feb 8th, 2007, 12:57 AM
#3
Thread Starter
Fanatic Member
Re: date time error
hi jmcilhinney,
i need to convet the following string as datetime
dim s as string="20/01/2007"
how to convert this string as datetime,please show me some example code
show me some sample code please
-
Feb 8th, 2007, 01:01 AM
#4
Re: date time error
You convert a string to a Date using Date.Parse, .ParseExact, .TryParse or .TryParseExact.
Having said that, you should avoid having to perfrom any conversions if possible. Where is that string coming from? If you're having the user enter it in a TextBox then may I suggest using a DateTimePicker instead?
-
Feb 8th, 2007, 01:11 AM
#5
Thread Starter
Fanatic Member
Re: date time error
hi jmcilhinney, actually i have my date in my database in the of sqlserver date format.but i am converting and retreiving and showing in datetime picker in "dd/mm/yyyy" format.
my date picker has the custom formate as "dd/mm/yyyy"
while retreiving i am getting date as string.so that only i want ot convert string as datetime.so show me some example code please
-
Feb 8th, 2007, 01:22 AM
#6
Thread Starter
Fanatic Member
Re: date time error
hi jmcilhinney
i used like this:
Dim d As DateTime = Date.Parse("20/01/2007")
but it also shows error not valid datetime.so help me to do
-
Feb 8th, 2007, 01:26 AM
#7
Re: date time error
I'm obviously not making myself clear. Do NOT, at ANY point, convert a Date to a String or a String to a Date because there is no need. You say your database contains datetime values, and a DateTimePicker contains a DateTime value too. Get the value from the database and assign it to the Value property of the DateTimePicker to display it. When you're done you get the Value property of the DateTimePicker and assign it back to the database. No strings, no converting, no problem.
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
|