•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 391,662 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,850 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 2505 | Replies: 4 | Solved
![]() |
The Date type has a Parse method that will try to convert a string to a date:
vbnet Syntax (Toggle Plain Text)
dim s_date1 as string dim s_date as date s_date1 = s_mon & "/" & s_day & "/" & s_year s_date = Date.Parse ( s_date1 )
Member of: Beautiful Code Club.
•
•
Join Date: Jan 2008
Posts: 24
Reputation:
Rep Power: 1
Solved Threads: 0
HI
dim s_date1 as stringdim s_date as dates_date1 = s_mon & "/" & s_day & "/" & s_years_date = Date.Parse ( s_date1 )dim s_date1 as string
dim s_date as date
s_date1 = s_mon & "/" & s_day & "/" & s_year
s_date = Date.Parse ( s_date1 )
After i use the above code i got the following error
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: FormatException
also i tried with following types of type cast from string to date
s_date = Convert.ToDateTime(s_date1)
s_date = Date.ParseExact(s_date1, "mm/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
s_date = DateTime.Parse(s_date1)
dim s_date1 as stringdim s_date as dates_date1 = s_mon & "/" & s_day & "/" & s_years_date = Date.Parse ( s_date1 )dim s_date1 as string
dim s_date as date
s_date1 = s_mon & "/" & s_day & "/" & s_year
s_date = Date.Parse ( s_date1 )
After i use the above code i got the following error
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: FormatException
also i tried with following types of type cast from string to date
s_date = Convert.ToDateTime(s_date1)
s_date = Date.ParseExact(s_date1, "mm/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
s_date = DateTime.Parse(s_date1)
Last edited by suganzeni : Mar 18th, 2008 at 2:04 am.
•
•
Join Date: Jan 2008
Posts: 24
Reputation:
Rep Power: 1
Solved Threads: 0
Hi
I found whats the problem.
The format exception is because i have given it as
s_date1 = s_mon & "/" &s_day & "/" & s_year
But the system format is (dd/mm/yyyy)
so after giving as like follows
s_date1 = s_day & "/" & s_mon & "/" & s_year
All type casting form string to date is working.
s_date = CType(s_date1, Date)
s_date = Date.Parse(s_date1)
Its just a simple mistake.
Because of not clear about the date format of the system.
Any way thanks for your help NARUE
I found whats the problem.
The format exception is because i have given it as
s_date1 = s_mon & "/" &s_day & "/" & s_year
But the system format is (dd/mm/yyyy)
so after giving as like follows
s_date1 = s_day & "/" & s_mon & "/" & s_year
All type casting form string to date is working.
s_date = CType(s_date1, Date)
s_date = Date.Parse(s_date1)
Its just a simple mistake.
Because of not clear about the date format of the system.
Any way thanks for your help NARUE
Right, the parse format is by default the system format. You can get around that incompatibility by constructing a date directly and then converting it to a date string with your desired format (if you need the string for anything else):
s_date = New Date ( s_year, s_mon, s_day ) s_date1 = s_date.ToString ( "MM/dd/yyyy" )
Member of: Beautiful Code Club.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
Similar Threads
- Object Orientated C+++.net Calculator! (C++)
- Casting or datatype conversion problem (VB.NET)
- Cast from string "" to type 'Integer' is not valid. (ASP.NET)
- Help with a cast error (ASP.NET)
- finding out variable type from html input type tag in javascsript (HTML and CSS)
- convert from 'ref double[]' to 'ref object' (C#)
- ADO.NET Specified cast is not valid (ASP.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Convert a word in kanji to katakana or vice-versa.
- Next Thread: Web robot



Linear Mode