Can anyone help me here? I don't have any idea why my code for calculating age is not working. Thank you for the response.
int year = Convert.ToInt32(passportApplicant.DateOfBirth.Year) - Convert.ToInt32(DateTime.Now.Year);
year should be returning a int value already no need to convert it.
also you should be subtracting nows time from the date of birth time (biggertime - smallertime)
your statement should look like this:
int year = DateTime.Now.Year - passportApplicant.DateOfBirth.Year
// 2020 - 2000 = 20 years old
or this gets you the exact year of birth
// this subtracts the passports year, month, and day from the time now
// leaving you with the difference between date born and the time now
int year = DateTime.Now.AddYears(-passportApplicant.DateOfBirth.Year).AddMonths(-passportApplicant.DateOfBirth.Month).AddDays(-passportApplicant.DateOfBirth.Month.day)).Year;
Hope this helps!
Edit:
little side note. try using datetime.UtcNow whenever possible especially when saving to a database. only use the users datetime.now when displaying. it will help you big time down the road as timezone will throw off everything
Related
Usually you can get this using LAST_DAY in esql but in app connect it's not working anyone has any idea on how to get last day of the month using esql in app connect?
I solved the problem I used intervals to get the next month then set the next month's date value to 1 and use interval again to get the day before, which will be the last date of the month in question.
Basically I checked the next month and got next month's 1st date which will always be 1 then got the day before that which will always be the last date of current month.
i want to set a daily alarm
but i can't convert the Hours and Minutes to Duration to make the Alarm work on time
so is there any Easy way to implement it
i was thinking in converting the time to DateTime and put the year month day etc etc
and then compare between them by Datetime.diffrence() method
like this
Duration duration = DateTime.now().difference(DateTime(DateTime.now().year,DateTime.now().month,DateTime.now().day,hour,minute));
but i think there is an easier way
so if someone can guide me :)
thank u
One option is to try and convert the hours and minutes to a duration something like below:
Duration time = new Duration(hours:2, minutes:3, seconds:2);
What I need to do is in my program i need to add the Arrival DATE and the Nights staying together and have it display into another textbox called Departure date. The format for the arrival date will be in the "##/##/##" context and the nights staying is an integer between 1 and 14.
I have all of the code for the rest of my program completed, I just do not know how to do this. I dont know how to take an integer and add it to a date so in the display box, after they are added together, it displays a date X amount of days after the arrival days. Where X is the Nights staying.
I Will greatly appreciate any help with this.
Use DateTime.AddDays to add number of days in the DateTime object like:
DateTime arrivalDate = new DateTime(2014,03,10);
DateTime departureDate = arrivalDate.AddDays(1); // Add One day
To get the formatted Date back use ToString with Custom DateTime Formats
string formattedDate = departureDate.ToString("dd/MM/yy", CultureInfo.InvariantCulture);
I want to know when is the New Month. So that I can do some operation
like, copy last month data [eg. Category.Title] from last month [Jan] to the new month [Feb].
Month Catagory
===== ========
Jan => Category.Title
Feb => New Category.Tile (copy based on Jan's data)
How do I construct the logic to detect that Today is a new month (so that I can preform the copy operation)?
Basically, I want to detect when is the New Month begin?
If all you need is the logic to check if today is the first day in a month, you can use the following code.
var d:Date = new Date();
if (d.date == 1) {
//today is the first day in a month
}
Depending on where/when you're doing this however, it may not have the effect you desire. Without more information, I can't really help you there.
You should employ this fabulous logic found on the provided link and go from there. Pretty much you need to find out if current date of the month. Lets say if today is the 15th of April, you will then need to find out how many days are there in April, 2012, and where does the 15th of April fall. And then have a counter count the remaining days until the new month (May) begins. You also want to make sure that you are checking for the leap year. This link also has a function that checks for the leap year. I am giving you a high level idea to go about getting what you trying to.
http://www.electrictoolbox.com/javascript-days-in-month/
Thanks a lot.
I want to use a asp.net drop down to present the user a delivery date on checkout. What I'm not sure about is how to get the specific dates. What the user should see and be able to select in the drop down is the next Monday and Tuesday for the next two weeks. Any help would be appreciated.
thanks.
The simplest solution is to use the DateTime.DayOfWeek property (http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx).
You start with getting today's date, or, if today is Monday and you can't deliver for two days, so the next delivery will be a week Monday, then start with tomorrow. I am not certain how you would handle if I order tomorrow could I get a delivery date for the next day, so I would need that clarified.
Get the day of the week, starting with either today or tomorrow, extracting it from a specific date as explained here:
http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx
If it isn't Monday or Tues then just determine how many days you need to reach Monday or Tuesday, then add that number of days and get that date, and then just add seven and get the date.
I would prefer to let .NET determine the date of seven days from now, as you may change month or years.
That is the basic approach. If you get stuck when trying to implement it, I would suggest some code so we can help you determine where you got stuck.
There are other approaches, but this is probably the simplest to understand and implement.
Here's a pretty simple suggestion using a lot of LINQ:
private void LoadDeliveryDays(int period)
{
DateTime[] days = Enumerable.Range(1, period).Select(i => DateTime.Today.AddDays(i)).ToArray();
DropDownList1.DataSource = (from d in days where d.DayOfWeek == DayOfWeek.Monday | d.DayOfWeek == DayOfWeek.Tuesday select d.ToString("dddd dd-MM-yyyy")).ToArray();
DropDownList1.DataBind();
}
You probably want to change the d.ToString("dddd dd-MM-yyyy") and/or what value is actually used in the dropdown.