PC Review


Reply
Thread Tools Rate Thread

datetime.now

 
 
mp
Guest
Posts: n/a
 
      10th Jan 2005
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


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      10th Jan 2005
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.

--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)


"mp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      10th Jan 2005
Hi mp,

DateTime d = DateTime.Now;

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

--
Happy Coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Millisecond values missing when inserting datetime into datetime column of sql Server Manikandan Microsoft C# .NET 4 18th Jul 2007 08:59 PM
How can I save a DateTime from my C# program into a SQL Server (datetime) database column. Steve Kershaw Microsoft ASP .NET 5 29th Aug 2006 03:10 AM
System.DateTime doesn't convert to SqlDbType.DateTime Narshe Microsoft C# .NET 3 2nd Nov 2005 05:42 PM
DateTime problem: how to create datetime format hh:mm:ss AM/PM without the date mimi Microsoft C# .NET 1 6th Aug 2004 08:28 PM
XML dateTime conversion to DateTime.MinValue accross timezones Symon R Microsoft Dot NET 0 6th Aug 2003 07:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:57 AM.