473,406 Members | 2,377 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,406 software developers and data experts.

Convert a date string

In VB6, I can format a date string like the following:
format("12/15/06","yymmdd") and it returns 061215.
In VB.Net, when I do the following:
sdate.tostring("yymmdd"), it gave me an error "Value of type string
cannot be converted to 'System.IFormatProvider'

How can I do it in VB.NET ?
Thanks.

Dec 15 '06 #1
9 12980
AFAIK the .ToString(...dateformat...) only works with a DateTime
object. Try this instead:

MessageBox.Show(Convert.ToDateTime("12/15/06").ToString("yyMMdd"))

Thanks,

Seth Rowe
fp***@yahoo.com wrote:
In VB6, I can format a date string like the following:
format("12/15/06","yymmdd") and it returns 061215.
In VB.Net, when I do the following:
sdate.tostring("yymmdd"), it gave me an error "Value of type string
cannot be converted to 'System.IFormatProvider'

How can I do it in VB.NET ?
Thanks.
Dec 15 '06 #2
I'm thinking he's using hungarian notation - so sdate is probably
declared as a string, not a datetime.

Thanks,

Seth Rowe
Kerry Moorman wrote:
fpvt2,

I did not have any problems getting the following code to work:

Dim d1 As DateTime = Now

Console.WriteLine(d1.ToString("yyMMdd"))

Maybe you can post the exact code that is giving you a problem?

Kerry Moorman
"fp***@yahoo.com" wrote:
In VB6, I can format a date string like the following:
format("12/15/06","yymmdd") and it returns 061215.
In VB.Net, when I do the following:
sdate.tostring("yymmdd"), it gave me an error "Value of type string
cannot be converted to 'System.IFormatProvider'

How can I do it in VB.NET ?
Thanks.
Dec 15 '06 #3

fp***@yahoo.com wrote:
In VB6, I can format a date string like the following:
format("12/15/06","yymmdd") and it returns 061215.
In VB.Net, when I do the following:
sdate.tostring("yymmdd"), it gave me an error "Value of type string
cannot be converted to 'System.IFormatProvider'

How can I do it in VB.NET ?
I guess you must convert the string to date first (something VB6 did
for you, automagically), and *then* format the date the way you want.
=)

I mean:

Dim D As String = _
Date.ParseExact(sDate, "mm/dd/yy", Nothing).ToString("yymmdd")

HTH

Regards,

Branco.

Dec 15 '06 #4
fp***@yahoo.com wrote:
In VB6, I can format a date string like the following:
format("12/15/06","yymmdd") and it returns 061215.
In VB.Net, when I do the following:
sdate.tostring("yymmdd"), it gave me an error "Value of type string
cannot be converted to 'System.IFormatProvider'
That's because VB 'Proper's Evil Type Coersion implicitly changed the
string value "12/15/06" into a Date value and then formatted /that/.

Visual Basic forces you to take more care over how things do things.
Formatting (ToString'ing) a String is very different from the formatting
a Date:

? DateTime.Parse( "12/15/06").ToString( "yymmdd" )

Or, since you start and end with Strings:

sDate.Substring( 6, 2 ) _
& sDate.Substring( 0, 2 ) _
& sData.Substring( 3, 2 )

HTH,
Phill W.
Dec 15 '06 #5
"rowe_newsgroups" <ro********@yahoo.comha scritto nel messaggio
AFAIK the .ToString(...dateformat...) only works with a DateTime
object. Try this instead:

MessageBox.Show(Convert.ToDateTime("12/15/06").ToString("yyMMdd"))
Pay attention with dates as "1/5/2006" where you can't tell if 1 is the day
or the month.

Dec 15 '06 #6
Thank you, eveybody.
Convert.ToDateTime("12/15/06").ToString("yyMMdd")) does it.

Thanks.
Fabio Z wrote:
"rowe_newsgroups" <ro********@yahoo.comha scritto nel messaggio
AFAIK the .ToString(...dateformat...) only works with a DateTime
object. Try this instead:

MessageBox.Show(Convert.ToDateTime("12/15/06").ToString("yyMMdd"))

Pay attention with dates as "1/5/2006" where you can't tell if 1 is the day
or the month.
Dec 15 '06 #7
fpvt,

Or in true VisualBasic
CDate("12/15/06").ToString("yyMMdd")

Cor

<fp***@yahoo.comschreef in bericht
news:11**********************@j72g2000cwa.googlegr oups.com...
Thank you, eveybody.
Convert.ToDateTime("12/15/06").ToString("yyMMdd")) does it.

Thanks.
Fabio Z wrote:
>"rowe_newsgroups" <ro********@yahoo.comha scritto nel messaggio
AFAIK the .ToString(...dateformat...) only works with a DateTime
object. Try this instead:

MessageBox.Show(Convert.ToDateTime("12/15/06").ToString("yyMMdd"))

Pay attention with dates as "1/5/2006" where you can't tell if 1 is the
day
or the month.

Dec 15 '06 #8

"Cor Ligthert [MVP]" <no************@planet.nlha scritto nel messaggio
news:uE*************@TK2MSFTNGP02.phx.gbl...
fpvt,

Or in true VisualBasic
CDate("12/15/06").ToString("yyMMdd")
I repeat: watch out for locale dates.
I don't think that the date "12/15/06" is hard coded.
I.e. in my country (Italy) that date does not exists, because 15 would be
the month (dd/mm/yyyy).

Dec 16 '06 #9
Fabio,

Normally I am the one who is writting as you did in the dotNet newsgroup.

I was missing the date completely.,

:-)

Cor

"Fabio" <zn*******@virgilio.itschreef in bericht
news:OF**************@TK2MSFTNGP04.phx.gbl...
>
"Cor Ligthert [MVP]" <no************@planet.nlha scritto nel messaggio
news:uE*************@TK2MSFTNGP02.phx.gbl...
>fpvt,

Or in true VisualBasic
CDate("12/15/06").ToString("yyMMdd")

I repeat: watch out for locale dates.
I don't think that the date "12/15/06" is hard coded.
I.e. in my country (Italy) that date does not exists, because 15 would be
the month (dd/mm/yyyy).

Dec 16 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a...
2
by: Remi Caron | last post by:
Hi, I took over an Visual Object project (Visual Clipper) in that language there is a function to: Convert a string containing a 32-bit binary date to a date data type. That function is called...
2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
1
by: ABC | last post by:
How to convert a date string to datetime value with custom date format? e.g. Date String Date Format Result (DateTime value) "05/07/2004" "MM/dd/yyyy" May 7, 2004 "01062005" ...
10
by: Kim Hellan | last post by:
I have a simple string in the format "DD-MM-YY hh:mm:ss", that I need to convert to a DateTime value. I know this is a standard problem, but please don't just link to all the MSDN pages regarding...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
4
by: Tony B | last post by:
I'm looking to convert a string in "dd/MM/yy" format into a date object. How do I go about this ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.