.net equivalent to datepart

  • Thread starter Thread starter Andy Sutorius
  • Start date Start date
A

Andy Sutorius

I am attempting to make a date string like this:

4-16-2004

with dashes instead of slashes

How would I code that? I assume datetime.now and then what?

Thanks!

Andy Sutorius
 
Never mind, I got it...is there a "better" way though?:

Dim dtmDate As DateTime
dtmDate = DateTime.Now()

Dim month As Integer
month = dtmDate.Month

Dim day As Integer
day = dtmDate.Day

Dim year As Integer
year = dtmDate.Year

Dim sdtmDate As String
sdtmDate = cstr(month) & "-" & cstr(day) & "-" & cstr(year)
 
Andy Sutorius said:
Never mind, I got it...is there a "better" way though?:

Dim dtmDate As DateTime
dtmDate = DateTime.Now()

Dim month As Integer
month = dtmDate.Month

Dim day As Integer
day = dtmDate.Day

Dim year As Integer
year = dtmDate.Year

Dim sdtmDate As String
sdtmDate = cstr(month) & "-" & cstr(day) & "-" &
cstr(year)

sdtmdate = dtmdate.tostring("MM-dd-yyyy")


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "Cor Ligthert said:
You see Armin, just because you write thx and I thanks, Herfried does
understand my answer and not yours.

I wondered why both of you replied with "thx" or "thanks".
 
Herfried K. Wagner said:
I wondered why both of you replied with "thx" or "thanks".

/I/ am usually the one (yes yes, of course not the only one) looking up the
online MSDN link. This time I forgot it although I read the article there.
:)
 
* "Armin Zingler said:
/I/ am usually the one (yes yes, of course not the only one) looking up the
online MSDN link. This time I forgot it although I read the article there.

OK, thank you for mentioning that the format should be specified in the
call to 'ToString' -- I forgot to mention that.
 
Back
Top