datetime.now

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

I am using :
SystemDate= System.DateTime.Now.Year.ToString()
+System.DateTime.Now.Month.ToString()+System.DateTime.Now.Day.ToString();

strbRetVal.AppendFormat("{0}{1}",SystemDate,m_chFieldDelimiter);



but this gives me : 200517

I want the date to look like: 20050107

How can I do this?



Thanks
 
mp,

You should make the call to DateTime.Now only once. You could have an
issue if this runs around midnight at the end of the year (very small, but
definitely possible).

Rahter, do this:

// Append the format.
strbRetVal.AppendFormat("{0:yyyyMMdd}{1}", DateTime.Now,
m_chFieldDelimiter);

That should work.

Hope this helps.
 
Hi mp,

DateTime d = DateTime.Now;

string s = d.ToString("yyyyMMdd");
 

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