Date conversion

  • Thread starter Thread starter bnob
  • Start date Start date
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
 
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.
 
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
 
Back
Top