By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,033 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,033 IT Pros & Developers. It's quick & easy.

Is there any function return 'yyyymm' ??

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl... 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

Nov 21 '05 #2

P: n/a
"Agnes" <ag***@dynamictech.com.hk> wrote in news:#iF85T1qEHA.348
@TK2MSFTNGP15.phx.gbl:
In my old vfp application, there is DTOS function to return 'yyyymm'
,in .net any similar function ??


Try Format:

http://msdn.microsoft.com/library/de...l=/library/en-
us/vblr7/html/vafctFormat.asp

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.