- Home /
Do if after date.
Hello,
I am currently working on a date actived system in my game project for special events (like chrismas event). I have sort of worked out how to get the current date but I have a issue with the code on how to do it. my idea is as bellow :
if (Todaysdate > Setdate){
// do stuff
}
But I dont belive it will be as easy as abve and would like some advice.
Answer by HarshadK · Jan 29, 2015 at 12:07 PM
You can get the current month using:
DateTime.Month; // You need to include using System at the top;
or directly with:
System.DateTime.Month;
And similarly you can get the day also with:
DateTime.Day; or System.DateTime.Day;
Now you can check this against the specific dates for which you want to check for.
Say you want to check for it is a time between December 25 and December 31:
if(System.DateTime.Month == 12 && System.DateTime.Day > 25 && System.DateTime.Day < 31)
{
// Do your stuff here
}
This is just one method. There are a lot of other Properties available under System.DateTime using which you can make them fit your exact need.
Answer by jaya rajpoot · Jan 29, 2015 at 12:08 PM
This may help. Try using variables like these and see how it goes. You do have to
theTime = System.DateTime.Now.ToString("hh:mm:ss"); theDate = System.DateTime.Now.ToString("MM/dd/yyyy"); theMonth = System.DateTime.Now.get_Month(); theDay = System.DateTime.Now.get_Day();
Your answer
Follow this Question
Related Questions
Get System date 1 Answer
Cleaning this code up. 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Fade in AudioLister over time #c 1 Answer