473,387 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can anyone help with setting default date in calender

hi

i have this code almost completed, apart from one small detail,

When the application starts, it should display the current date in the arrival date and the current date plus three days in the second departure date.

i have the arrival date working but i cant set the departure date,

i know its something like .AddDays(3), but when i put this to departure date it adds 3 days to total price instead of date begining 3 days ahead of current date.

could someone please help me out

Expand|Select|Wrap|Line Numbers
  1. private void btnCalculate_Click(object sender, EventArgs e)
  2.         {
  3.             DateTime currentDate = DateTime.Today; // set current date to today
  4.  
  5.             DateTime aTime, dTime; // arrival date, departure date //
  6.  
  7.             aTime = (dateTimePicker1.Value).Date; // arrival date in calender 1
  8.             dTime = (dateTimePicker2.Value).Date; // departure date in calender 2
  9.  
  10.  
  11.             int nights = 0;
  12.  
  13.                 TimeSpan totalStay = dTime - aTime;
  14.                 nights = totalStay.Days;
  15.                 txtNoNights.Text = nights.ToString();
  16.  
  17.             int selectedIndex = cboRoomType.SelectedIndex;
  18.             if (selectedIndex != 0)
  19.             {
  20.                 decimal price = Convert.ToDecimal(rooms[selectedIndex, 1]);
  21.                 decimal result = nights * price;
  22.                 txtTotal.Text = result.ToString("c");
  23.             }
  24.             else
  25.             {
  26.                 MessageBox.Show("Please select a Room Type", "Invalid Room");
  27.             }
  28.  
  29.         }
  30.  
thanks to anyone who helps out
Dec 9 '11 #1

✓ answered by adriancs

Youtube video
DateTimePicker Tutorial, watch this:
http://www.youtube.com/watch?v=9I8BVf5raHo

14 2326
adriancs
122 100+
just preset the value of dateTimePicker.
Expand|Select|Wrap|Line Numbers
  1. dateTimePicker1.Value = DateTime.Today;
  2. dateTimePicker2.Value = DateTime.Today.AddDays(3);
by the way,
Expand|Select|Wrap|Line Numbers
  1. (dateTimePicker1.Value).Date
has the same value as
Expand|Select|Wrap|Line Numbers
  1. dateTimePicker1.Value
this should be ok
Expand|Select|Wrap|Line Numbers
  1. aTime = dateTimePicker1.Value;
  2. dTime = dateTimePicker2.Value;
Dec 11 '11 #2
thanks for replying adriancs, but your reply does not work, it only adds 3 days to the total stay, instead of - When the application starts, it should be displaying the current date plus three days in the departure date.

In your answer the departure date stays the dame all the time and does not allow user to enter selection of date,
Dec 11 '11 #3
Hi if you don't mind can you explain me about total stay means..and
are you using calendar control or is there any other control..if you clarify me i will give you replay soon..
Dec 12 '11 #4
adriancs
122 100+
Ok, lets take an example:

John's traveling schedule:
arrival date is: 12 Dec 2011
departure date is: 15 Dec 2011
Price of 1 night is: $50

Calculation:
Payment = ((15 Dec 2011) - (12 Dec 2011)) * $50

is this what you want?
Dec 12 '11 #5
No not that.I need your page screen shot..can you provide that screen shot and tell me what exactly you need..because
DateTime dt1 = DateTime.Today; if this works fine then
it should support the following statement
DateTime dt2 = DateTime.Today.AddDays(3);
correct me if i understand wrong
Dec 12 '11 #6
what is name of dateTimePicker1 control..
Dec 12 '11 #7
Brian Connelly
103 100+
So your calculation would return 3 days, but you want the total nights so you need subtract 1 from the total days to give you night stays. For the second calender, use an if statement which I have not build out. What you could do is set the dTime = aTime.AddDays(3) which allows the departure date to default to 3 days from whatever date aTime is. The if statement should check to see if dTime has changed.
Dec 12 '11 #8
sorry i got your point...what you have to do is just select the datetime picker from design and right click on it then select properties then set Value attribute to your date then it will work fine...you no need to write any code in click event of button because you need the values when you run the application but not at the time of clicking on button...got it ..correct me if i understand wrong
Dec 12 '11 #9
@adriancs

what i have to do is Create a hotel reservations form that accepts an arrival and departure date for a reservation from the user. The form should allow the user to select a room type from a list (single, double, king and suite) and then calculate the number of nights and the total price for the reservation.


I have the program working apart from one small detail in the specifiaction that says to

"When the application starts, it should display the current date in the first text box and the current date plus three days in the second text box. That way, the user can modify these default dates as necessary"



when i put dateTimePicker2.Value = DateTime.Today.AddDays(3);, it adds 3 days to current date, and does not allow user to change to users selected date
Dec 12 '11 #10
adriancs
122 100+
--------- deleted ----------
Dec 12 '11 #11
adriancs
122 100+
from the picture that you've uploaded. I can see that, the user is able to change the arrival and departure date.
Isn't it? With or without value preset.
Dec 12 '11 #12
adriancs
122 100+
Hi, I have quickly make a simple form base on the uploaded picture.
may have a look here:
http://www.mediafire.com/?kezm2m2jpoe1d08
Dec 12 '11 #13
adriancs
122 100+
Youtube video
DateTimePicker Tutorial, watch this:
http://www.youtube.com/watch?v=9I8BVf5raHo
Dec 13 '11 #14
thanks for the help adriancs, I finally got it working
Dec 13 '11 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Anna | last post by:
I am an extreme newbie to Access and need help setting a default date on a form. The situation is: I have a field called date_received which is set to default to today's date. I have another...
4
by: Jeff Cope | last post by:
I'd like to have a text box on my webform and a button beside that will set the current date in the text box when the button is clicked. Is there a way to do this without doing a postback? ...
2
by: Rani | last post by:
guys I've created 3 combo boxes for a month date and a year how do I set the value to be the default date ? is there a more suphisticated way to do so ? herein is the code i am using <select...
2
by: Robbie De Sutter | last post by:
Hello, How do I open a new, empty e-mail message from the default e-mail client whereby the sender is given and a file is attached? Currently I use the command (vb.net): ---...
12
by: Yannick | last post by:
Hi, I've got a problem accessing a ms-access db with a sql statement like this: SELECT * FROM laTable WHERE laDate = #05/21/2004# ; with asp.net (vb code) laTable contains a "laDate"...
1
by: DawnAnne1974 | last post by:
I need to set a default date on a form that when it comes to a Monday, the form from and to dates will default to the Friday to Sunday of the previous week. For all other day, the form should...
9
by: Rizwan Karedoa | last post by:
Hi experts, I am developing an application, I am using vb 2005 and access. I have many date fields, When I am saving through Query for default date I save 1/1/1500 so when i find that date agian I...
3
by: dpmcdoug | last post by:
I am a relative novice with Access and I am developing an input form that I need a default date to populate, regardless of the input date e.g. If I input data on Tuesday, Sept 27, I want the default...
0
by: HockeyFan | last post by:
Does anyone know how to have a default date for the CalendarExtender? I'd prefer that the textbox it is associated with, remain blank until the user actually clicks on it, but I also don't want...
3
by: BurtonBach | last post by:
This question is in regards to a text box on a form in Access. Is there a way to make the default value setting default to the first day of the current month?
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.