Get dateformat in yyyymm

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

If my input date is 2004-02-05, I want to get '200402'
Can anyone know the simple way to do ? Thanks a lot
 
Dim d As DateTime = "2004-02-05"

MessageBox.Show(d.Year.ToString("0000") & d.Month.ToString("00"))
 
Agnes said:
If my input date is 2004-02-05, I want to get '200402'
Can anyone know the simple way to do ? Thanks a lot

\\\
MsgBox( _
Date.ParseExact( _
"2004-02-05", _
"yyyy-MM-dd", _
Nothing _
).ToString("yyyyMM") _
)
///
 
Agnes

MyResultString = MyOriginalString.substring(0,4) &
MyOriginalString.substring(5,2)

I hope this helps?

Cor

"Agnes"
 
Agnes said:
If my input date is 2004-02-05, I want to get '200402'
Can anyone know the simple way to do ? Thanks a lot

To add another possible solution:

Dim d As DateTime = DateTime.Parse("2004-02-05")
MessageBox.Show(Format(d, "yyyyMM"))
 
Agnes said:
If my input date is 2004-02-05, I want to get '200402'
Can anyone know the simple way to do ? Thanks a lot

Dim dtThen as DateTime _
= CDate( "2004-02-05" )

Console.Writeline( dtThen.ToString("yyyyMM") )
' NB: That's "MM", not "mm"

HTH,
Phill W.
 

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

Back
Top