Adding a number to a date - asp.net

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);

Related

Calculating age from birthdate year to current date in ASP.NET MVC

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

Date format in lotus notes

I have a lotus notes field which should save the date/time in the GMT format,
for that I used
Dim timenow As Variant
timenow = Now()
Dim dateTime As New NotesDateTime( timenow )
doc.abc = dateTime.GMTTime
This will set the field 'abc' to have the date and time in GMT. But now I am having issues with the date format. In my system it saves it in the format 10/28/2016, but for other users whose system date format is different, it saves it in the format 28.10.2016. I need to force the date format to be 10/28/2016, I tried used format function
doc.abc = Format(dateTime.GMTTime, "m/d/yy h:nn")
The above code gives the date and time in GMT, but doesn't change the date format.
You are wrong in the assumption, that the date is SAVED in that format.
Date items in the backend are number- items. They store the date as number, the integer part is the day, the fraction part is the time of the day (day 0 is 12/31/1899 00:00)
Then the setting in the client determins, how the client displays the date.
In the properties of the item you usually define "Client" as display format, but you could fix the display of the date to a specific form.
But usually this is NOT necessary, and every german will not like the "reversed" order of english / american time formatting.
This will only be a problem, if you construct a text from that date, as #Text() will convert it using the clients format.
I guess, that your problem is not in the "saving" of the item, but somewhere else in your code, where you interpret the date as text, and this is always a problem.
What type of field is it? If it's a date field, the Notes client will use the user's local date format.
If you want to use a specific format, you can use a text field instead, but of course then the time won't adjust to the user's local time zone.
The way to get the best of both worlds is to store the date in date field, but use a computed-for-display field to show it in the user's current timezone, but in exactly the format that you want.
Most people use a NotesDateTime object to set the date in a field
Dim ExpiryDate As New NotesDateTime(Cstr(Today))
Even if the field in the form uses a specific format, the date like 2019-09-08 can mean 8th september 2019 or 9th august 2019 depending of the LocalDate setting
To avoid this behavior, you need to force the format in your NotesDateTime Object
Like this
Dim ExpiryDate As New NotesDateTime(Format$( Today, "yyyy-mm-dd "))

Symfony 2 - Generate calendar month table with links to events in it

I have an Entity called Event, with fields startDate, startTime, endDate and endTime. startDate and endDate are dates of which endDate can be NULL if it is the same of startTime (I can change this behaviour if it makes things easier as I have no events yet). startTime and endTime can not be NULL. It also has an isOnDate(\DateTime $date) method, which returns true if the event will run on the given date.
It was like pain, but I finally generated an HTML table of any given calendar month, passing the day of week of the month's first day (firstDow) and the number of days in that month (numDays) as template variables.
The next step would be to make some table cells links to event or event listing pages if the given days has one or more events. Now I'm a bit stuck, as I don't know how to get the DateTime() object of each cell in a template.
Can someone give me a hint on this? Or am I making it totally wrong?
You can display DateTime Objects as Text Dates using Twig Filter date:
{{ event.startDate|date("m/d/Y") }}
You could use Ajax and jQuery to link dynamically your page with your database. You could start from this calendar code for Symfony2: http://www.symfocal.com

ASP.NET Linq where filters checking dates not working

So on my page I have two date boxes where users can choose a from and to date. The problem is when I enter for example the below. I get items which actually have a date greater than 05/04/2012, which according to the below should not happen.
Basically what I am trying to achieve is
If from date is entered then date >= from date
if to date is entered then date <= to date
if both are entered then date >= from date and date <= to date
This is happening because your cl.claimStatus.Any will return true if any of the items in the claimStatus list are less than 05/04/2012. Thus, your statement would look like the following:
filteredClaims = filteredClaims.Where(c1=>true);
...thus returning everything.

Drop Down Date Delivery

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.

Resources