Console DateTime question

Trying to keep it short.

Page 1 of 1

2 Replies - 937 Views - Last Post: 09 August 2009 - 03:00 PM Rate Topic: -----

#1 AGRAC393   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

Console DateTime question

Post icon  Posted 09 August 2009 - 02:07 PM

Hello all,

I'm trying to keep this program short, around 20 lines if possible. What I'm trying to do is use DateTime to get the current date (MM-dd-yyyy) then compare it to a preset value. It's going on my 16th birthday cake (hehe) so I would like to keep it short as mentioned. Here is what I have tried, I'm still very new, so please be nice.

		DateTime date = DateTime.Now;
		string format = "MM-dd-yyyy";
		Console.WriteLine(time.ToString(format));

		if (date == 8-20-2009)



It says "Operator '==' cannot be applied to operands of type 'System.DateTime' and 'int'. Can anyone help me out with this? I think it's because I don't have the date in a variable... But I don't know how to put it in one!

Any suggestions?

Thanks for anything you can provide, ;)
Aaron

Is This A Good Question/Topic? 0
  • +

Replies To: Console DateTime question

#2 janne_panne   User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Console DateTime question

Posted 09 August 2009 - 02:40 PM

Here is a small snippet. It gets todays date and sets your birthday into another datetime object and then compares them with CompareTo method:

			DateTime today = DateTime.Today;
			DateTime bday = new DateTime(2009, 8, 20);

			if (today.CompareTo(bday) < 0) {
				// not yet 
			}
			else if (today.CompareTo(bday) == 0) {
				// whii, birthday!
			}
			else {
				// oh damn, no more birthday until next year.
			}


Was This Post Helpful? 1
  • +
  • -

#3 AGRAC393   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

Re: Console DateTime question

Posted 09 August 2009 - 03:00 PM

SWEET! Thank you! Problem solved!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1