DateString convert

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

I would like to get the string in this format: yyyyddmm , like in sql.

I read the date from the calendarControl:

dateString=Calendar.SelectedDate.Date.ToShortDateString

and I get dateString=4.12.2003

I would like to have:dateString=12042003

What is the best way to do that?

Thank you,

Simon
 
* "simon said:
I would like to get the string in this format: yyyyddmm , like in sql.

I read the date from the calendarControl:

dateString=Calendar.SelectedDate.Date.ToShortDateString

'<...>.Date.ToString(<format>)'.
 
Try the following code: y=year, M=month, d=day

Dim strDate as String = Format(DateTime.Now, "yyyyMMdd")
 
simon said:
I would like to get the string in this format: yyyyddmm , like in
sql.

I read the date from the calendarControl:

dateString=Calendar.SelectedDate.Date.ToShortDateString

and I get dateString=4.12.2003

I would like to have:dateString=12042003

What is the best way to do that?

Use the Date's ToString method instead of ToShortDateString. You can pass
the needed format to ToString.
 
simon said:
I would like to get the string in this format: yyyyddmm , like in sql.

SQL does not have a date format.
It can apply formatting to values as they are returned to you but,
internally, the database can store the data any way it darn well
pleases (and it'll be nothing like anything you or I can make sense
of).
I read the date from the calendarControl:
dateString=Calendar.SelectedDate.Date.ToShortDateString
and I get dateString=4.12.2003

which is exactly what you asked for.

If you want a /specific/ format, then format the Date the way
you want it to be, as in

dateString = Calendar.SelectedDate.Date.ToString( "ddMMyyyy" )

Bear in mind that VB will have a Devil of time trying to turn this
eight-digit number back into a Date, if you ever ask it to...

HTH,
Phill W.
 
YYYYMMDD
Bear in mind that VB will have a Devil of time trying to turn this
eight-digit number back into a Date, if you ever ask it to...

Microsoft.VisualBasic.DateAndTime.DateSerial()

Although, that's not really the ".NET Way".
--
Peace & happy computing,

Mike Labosh, MCSD
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
 
Back
Top