|
-
Mar 31st, 2006, 12:05 AM
#1
Thread Starter
Member
[02/03] Changing a string to a date
I'm using VB.NET 2003 version.
When reading a date from a file it is provided to VB as a string, right? So I have "dateShown" as the variable that the line from the file is stored too. How can I convert the data in the string into a date?
Last edited by Hack; Mar 31st, 2006 at 07:43 AM.
Reason: Added version to thread title
-
Mar 31st, 2006, 12:59 AM
#2
Re: Changing a string to a date
The handy search function on this forum will pull several examples, dont forget that its there...
http://www.vbforums.com/search.php?q...0&saveprefs=1&
-
Mar 31st, 2006, 07:43 AM
#3
Re: [02/03] Changing a string to a date
I've edited your thread title to include the version that you specified in your message body. This helps people that want to help you know what sort of coding advice to provide.
Please use the radio buttons provided to specify what version you are using when creating new threads in the future.
Thanks.
-
Mar 31st, 2006, 11:32 AM
#4
Thread Starter
Member
Re: [02/03] Changing a string to a date
In all of the examples I find it has an exact date converted into an exact date of a different format. If I don't know the exact date, because I am reading it from a file, how can I still change it to the format I want it to be in?
Thanks
-
Mar 31st, 2006, 11:43 AM
#5
Re: [02/03] Changing a string to a date
A string is a string is a string. You pass the string you read from the file to whatever method you are using. You can use Parse or ParseExact. If the string contains a date in one of the recognised standard formats then use Parse. If it contains a known, non-standard format then use ParseExact. If you have no idea what format it will be in then you have a problem. You can use Parse and catch any exception that might be thrown, then try ParseExact with some likely alternatives but generally speaking data to be read by computer programs should have some consistent structure to it.
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
|