By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

formatting Dates?

P: n/a
JD
I would like to know what is the preferred/best way to
format date values in VB.Net. Here is what I have

Dim str1 As String
str1 = txtDate.Text 'say 2/3/2005

I need 2/3/2005 to be 03FEB2005. Here is what I tried

str1 = txtDate.Text.ToString("ddMMMyyyy")

but I got an error message about System.IFormatProvider
something missing. I tried Imports System, still error.
So I then tried

str1 = Format(txtDate.Text, "ddMMMyyy")

which did work, and also tried

str1 = String.Format("ddMMMyyyy", txtDate.Text)

which also worked. But I know I have seen the
txtDate.Text.ToString("ddMMMyyyy") method somewhere. So
could someone suggest what is the preferred method to
format dates in VB.Net?

Thanks,
JD
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"JD" <an*******@discussions.microsoft.com> schrieb:
I would like to know what is the preferred/best way to
format date values in VB.Net. Here is what I have

Dim str1 As String
str1 = txtDate.Text 'say 2/3/2005

I need 2/3/2005 to be 03FEB2005. Here is what I tried

str1 = txtDate.Text.ToString("ddMMMyyyy")

but I got an error message about System.IFormatProvider
something missing. I tried Imports System, still error.


You will have to convert the string to a 'Date' first:

\\\
Dim d As Date = DateTime.Parse("22/02/1999")
MsgBox(d.ToString("ddMMMyyyy"))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2

P: n/a
The format codes you are using apply to a DateTime variables, not string
variables. You need to get the date in question into a DateTime variable.
Try something like:
Dim d As DateTime = Now
Dim s As String = d.ToString("ddMMMyyyy")
"JD" wrote:
I would like to know what is the preferred/best way to
format date values in VB.Net. Here is what I have

Dim str1 As String
str1 = txtDate.Text 'say 2/3/2005

I need 2/3/2005 to be 03FEB2005. Here is what I tried

str1 = txtDate.Text.ToString("ddMMMyyyy")

but I got an error message about System.IFormatProvider
something missing. I tried Imports System, still error.
So I then tried

str1 = Format(txtDate.Text, "ddMMMyyy")

which did work, and also tried

str1 = String.Format("ddMMMyyyy", txtDate.Text)

which also worked. But I know I have seen the
txtDate.Text.ToString("ddMMMyyyy") method somewhere. So
could someone suggest what is the preferred method to
format dates in VB.Net?

Thanks,
JD

Nov 21 '05 #3

P: n/a
JD
Thanks for everyone's help. That is what I was missing -
it was from the date variable, not the string.
-----Original Message-----
I would like to know what is the preferred/best way to
format date values in VB.Net. Here is what I have

Dim str1 As String
str1 = txtDate.Text 'say 2/3/2005

I need 2/3/2005 to be 03FEB2005. Here is what I tried

str1 = txtDate.Text.ToString("ddMMMyyyy")

but I got an error message about System.IFormatProvider
something missing. I tried Imports System, still error.So I then tried

str1 = Format(txtDate.Text, "ddMMMyyy")

which did work, and also tried

str1 = String.Format("ddMMMyyyy", txtDate.Text)

which also worked. But I know I have seen the
txtDate.Text.ToString("ddMMMyyyy") method somewhere. So
could someone suggest what is the preferred method to
format dates in VB.Net?

Thanks,
JD
.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.