Candyfloss
Candyfloss

Reputation: 3908

Format DateTime.Now

A peculiar request this one.

I am looking to compare two times in C#.

I have:

DateTime systemDate = DateTime.Now.AddMinutes(-15);
//which I presume subtracts 15 minutes from the current time

I am then reading in an ftp file from a Fedora server containing a date and time that I am reading in as a stream and converting to a DateTime

2011-03-17 09:00:18.000000000 +0000

I then parse this:

compareDate = DateTime.Parse(streamer);

My Question therefore is how do I format systemDate to be in the same format as the one I have parsed in compareDate? I am aware you can format DateTime but all of the sites I have seen so far dont have it in this format.

Thank you in advance, feel free to comment if you think I have missed anything :)

Upvotes: 1

Views: 8605

Answers (3)

Furqan Hameedi
Furqan Hameedi

Reputation: 4400

You can do it like this,

DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

Upvotes: 7

Kris Ivanov
Kris Ivanov

Reputation: 10598

just use var systemDate = DateTime.UtcNow.AddMinutes(-15); for your original one, then you just

if (DateTime.Equals(systemDate, compareDate))
{
    //...
}

Upvotes: 1

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174427

No need to format systemDate, because you already parsed the date from the FTP server into a DateTime. You can just compare systemDate with compareDate.

Upvotes: 2

Related Questions