473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

formatting Dates?

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
3 5146
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
163
by: Shiperton Henethe | last post by:
Hi Know any good utilities to help me strip out the tags that Microsoft Excel 2002 leaved behind when you try and export an HTML format file? This is driving me NUTS. And really makes me...
2
by: Ange T | last post by:
Hi there, I've read stacks of articles on this subject in this newsgroup, so forgive me that this is just another one. I've tried almost all the suggestions offered, and am still having no luck....
3
by: Steve Weixel | last post by:
I'm having problems getting dates to format the way that I need them to. The problem is that I'm used to the VB6 way of doing things, with which the statement Format(37866, "dd MMM yyyy") would...
7
by: Middletree | last post by:
I am trying to display dates in a spreadsheet, but the dates need to be in a format that will allow them to be sorted in Excel. The datatype in the SQL Server database is datetime. In this case, I...
2
by: sgtted71 | last post by:
I have searched the Word Help and the Access Help, I have consulted the well used Access Bible that sits behind my desk, and to no avail...so now I consult the mighty brain trust that is...
7
by: sherifffruitfly | last post by:
Hi, God I hate datetime string formatting... How do I get a string of the form "04-Oct-2006", for example, from a DateTime object? Thanks a jillion, cdj
12
by: tarscher | last post by:
Hi all, A simple problem that seems hard to solve... I have a gridview with a date row. <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("time") %>'></asp:Label>...
0
by: macbasic | last post by:
Hi, I am a learner who is automating some data from reports to ease my month end pressures. The code below is used to open a text file (a report from our ERP) and seperate the text into columns. Two...
3
by: myemail.an | last post by:
If I need to format how the content of a field is displayed, I can click ALT + ENTER from design view, and specify the format, for example, the number of decimal digits and so on. Is there a way...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.