|
-
May 11th, 2006, 07:45 AM
#1
Thread Starter
Addicted Member
[Resolved] Help with converting date!
I am trying create code that prompts a user for the date in "mm/dd/yy" form then will display in a messagebox as "Month day, year".
Example: 05/11/06 - will display - May 11, 2006
I tryed using select case for it, but that didn't work to well for me, and is probably longer then another way out there. Could somebody please help?
Thanks.
Last edited by hlstriker; May 11th, 2006 at 08:03 AM.
Reason: Resolved
-
May 11th, 2006, 07:51 AM
#2
Re: Help with converting date!
VB Code:
Dim dateString As String = "05/11/06"
Dim myDate As Date = Date.ParseExact(dateString, "dd/MM/yy", Nothing)
MessageBox.Show(myDate.ToString("MMM dd, yyyy"))
-
May 11th, 2006, 07:54 AM
#3
Hyperactive Member
Re: Help with converting date!
If the user is prompted for a date using a DateTimePicker control then it is really easy.
The reuslt of the DateTimePicker will be it DateTimePicker.Value - which is a Date type,and as succh can be redisplayed using a ToString
ie, dtpInputDate.Value.Tostring("mmm dd, yyyy")
If you are using a textbox or similar to enter the date (and why - the datetimepicker is so much more user friendly) then your best bet is to convert the textstring to a date type.
I am pretty sure that
VB Code:
dim objDate as Date
objDate = ctype(txtInput.Text, Date)
Will not work in format dd/mm/yy - and besides if the user makes a mistake typing it in, the cast will cause an exception to occur.
Is there any reason you dont want to use a datetimepicker?
-
May 11th, 2006, 07:57 AM
#4
Hyperactive Member
Re: Help with converting date!
or you can just do what jmcilhinny suggests
-
May 11th, 2006, 07:57 AM
#5
Thread Starter
Addicted Member
Re: Help with converting date!
Is this allowing input of any date? It seems this is just getting the date from the computer. I was trying to input any date in "mm/dd/yy" form into a textbox, then it would convert it to the "Month day, year" form displaying it in a messagebox.
I probably should have used more examples in my first post. Sorry @_@
Examples:
06/18/02 - will display - June 18, 2002
05/11/06 - will display - May 11, 2006
-
May 11th, 2006, 08:01 AM
#6
Hyperactive Member
Re: Help with converting date!
substitute your txtbox.text for jmc's datestring
VB Code:
Dim myDate As Date = Date.ParseExact(txtbox.Text, "dd/MM/yy", Nothing)
MessageBox.Show(myDate.ToString("MMM dd, yyyy"))
-
May 11th, 2006, 08:03 AM
#7
Thread Starter
Addicted Member
Re: Help with converting date!
Ok, thanks alot everyone !
-
May 11th, 2006, 08:04 AM
#8
Hyperactive Member
Re: [Resolved] Help with converting date!
You may want to stick a try/catch block around it though otherwise it will all go titsup if the user types in garbage.
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
|