7 Replies - 3985 Views - Last Post: 09 December 2010 - 11:05 AM Rate Topic: -----

#1 3rdgunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-December 10

date time picker C#

Posted 07 December 2010 - 04:54 AM

I have 2 date time pickers and the user can select the dates he want and the program will show the number of week days Saturdays and Sundays. when I try to get the date time picker value and store it in an integer it says Cannot implicitly convert type 'int' to 'System.DateTime'. How can i convert it to an int
dtpStartDate.Value = startDate;

Is This A Good Question/Topic? 0
  • +

Replies To: date time picker C#

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,214
  • Joined: 23-August 08

Re: date time picker C#

Posted 07 December 2010 - 05:52 AM

Learning to read your errors is important.

Cannot implicitly convert type 'int' to 'System.DateTime'


When you get this error, the first type listed is the one on the right side of the =, the second on the left. So you're attempting to assign an integer value, startDate, to a DateTime object, dtpStartDate.Value. Therefore what you NEED to do is convert the integer value to a DateTime object, which -- depending on the content of startDate -- may be as simple as creating a DateTime object and passing startDate as the constructor argument.
Was This Post Helpful? 2
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: date time picker C#

Posted 07 December 2010 - 05:58 AM

The value of a DateTimePicker is a DateTime structure, not an integer. See DateTimePicker.Value Property

The DateTime Structure has a a Ticks property that returns a long integer. See DateTime.Ticks Property

You may want to look at TimeSpan Structure also.
Was This Post Helpful? 0
  • +
  • -

#4 3rdgunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-December 10

Re: date time picker C#

Posted 09 December 2010 - 09:45 AM

i still cant find how to do it can someone please tell me the code i need to use to do it
Was This Post Helpful? 0
  • +
  • -

#5 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: date time picker C#

Posted 09 December 2010 - 09:56 AM

Please post your code. Don't forget to use the code tags:

:code:
Was This Post Helpful? 0
  • +
  • -

#6 3rdgunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-December 10

Re: date time picker C#

Posted 09 December 2010 - 09:59 AM

I don't know what i need to do for the code but this is what i came up with, it isn,t correct as it still give me the same error as before
startDate = dtpStartDate.Value;

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,214
  • Joined: 23-August 08

Re: date time picker C#

Posted 09 December 2010 - 10:02 AM

No...show your WHOLE CODE, not just the single line that's causing the error. Or at least provide more information on where you're getting the data that you're attempting to use to populate the DateTimePicker.
Was This Post Helpful? 0
  • +
  • -

#8 3rdgunner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-December 10

Re: date time picker C#

Posted 09 December 2010 - 11:05 AM

      int startDate;     
            txtWeekDaysRate.Text = "10";
            txtSaturdaysRate.Text = "15";
            txtSundaysRate.Text = "20";

            startDate = dtpStartDate.Value;

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1