Date conversion

B

bnob

My regional setting is "yy-MM-dd" for the date

But for my application I have to use the format date "dd/MM/yyyy"
I convert the date to dd/MM/yyyy with this code :

m_curSel.ToString("dd/MM/yyyy")

But I have error : "Cast of the string "23-12-2004" in type Date is non
valide"

WHY ?

Another question : it's possible to use date variable independing of
the regional setting of the PC
 
H

Herfried K. Wagner [MVP]

bnob said:
My regional setting is "yy-MM-dd" for the date

But for my application I have to use the format date "dd/MM/yyyy"
I convert the date to dd/MM/yyyy with this code :

m_curSel.ToString("dd/MM/yyyy")

Is 'm_curSel' a 'Date' variable?

Your code works fine for me. If you want to use the "/" character as
separator:

\\\
MsgBox(Date.Now.ToString("dd\/MM\/yyyy"))
///
But I have error : "Cast of the string "23-12-2004" in type Date is non
valide"

I don't see where you cast a string into a date. Your code is converting a
date to a string, I assume. You can use 'DateTime.ParseExact' to convert a
date string that is in a specific format into a date.
Another question : it's possible to use date variable independing of the
regional setting of the PC

'Date' is independent from regional settings. Both, 'DateTime.ParseExact'
and 'DateTime.ToString' can be used to parse/output date strings by
specifying a certain date format string.
 
C

Cor Ligthert

Bnob,

In addition to Herfried (how is it possible about dates).

Your email adres is in Swiss, so you make me curious. I have always seen
there dates as "dd-MM-yyyy" is that changed the last months?

However when your culture setting is still the as the rest from Europe, than
you can use to make it culture independent by using

dim mystring as string = date.now.tostring("d")

I hope this helps

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top