Is there any function return 'yyyymm' ??

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

Agnes

In my old vfp application, there is DTOS function to return 'yyyymm'
,in .net any similar function ?? DTOS(datetime.now) and return yyyymm,
I know that I can CType(Year(datetime.now), String) &
CType(Month(datetime.now), String)
but if the datetime is Sep,04, it will return 20049 , but not 200409,
Anyone got the idea ? thanks a lot
 
Agnes,
I know that I can CType(Year(datetime.now), String) &
CType(Month(datetime.now), String)
I would strongly recommend against that, as what happens if you get the year
a fraction of a second before midnight & the month a fraction of a second
after midnight on Dec 31? I would recommend you save DateTime.Now into a
DateTime variable, then extract the parts that you need...

FWIW: You can use DateTime.Year in addition to the VB.Year function, same as
DateTime.Month in addition to the VB.Month function.

In my old vfp application, there is DTOS function to return 'yyyymm'
,in .net any similar function ?? DTOS(datetime.now) and return yyyymm,

I would use DateTime.ToString such as:

Dim s As String = DateTime.Now.ToString("yyyyMM")

The "yyyy" says a 4 digit year, the "MM" says 2 digit month ("mm" is used
for 2 digit minutes).

For details on custom datetime formats see:

http://msdn.microsoft.com/library/d...s/cpguide/html/cpcondatetimeformatstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp

Hope this helps
Jay
 
Agnes,

I have made a while that mistake with the mm and MM as well forever.
It has to be MM for months

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

Back
Top