Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day everyone please i want to convert int to date time but i am getting an error

Additional information: Invalid cast from 'Int32' to 'DateTime'.


What I have tried:

TimeSpan ts = retdt - reqdt;

           int days = ts.Days;

       DateTime cde = Convert.ToDateTime(days);


           if (cde <=before)
           {
               result = Convert.ToDouble(txtamount.Text);
               double mult = result * 5d;
               txtresult.Text = mult.ToString();
Posted
Updated 25-May-19 8:40am
Comments
BillWoodruff 26-May-19 0:51am    
This is a continuation of the same question you posted a day ago: https://www.codeproject.com/Answers/5046772/How-to-calculate-months-between-two-datetimepicker#answer2

It's clear you need to do some basic study of what DateTime and TimeSpan structures are.

Revise your original question and/or respond to the answers you already received.

Quote:
How to convert int to datetime in C# windows form

Almost same answer as your previous question.
A number is not a date. If the number is a number of days, you are missing the starting point, the initial date.
 
Share this answer
 
You're going to have to find out when the int value starts. Integer date/time values start from a certain date and time and count up a number of either seconds, milliseconds, ticks, ... to represent a date/time relative to the start.

For example, a C commonly uses 00:00:00 Jan 1st, 1970 for the starting time and the 32-bit integer that represents a date/time is the number of seconds since then. That clock runs out just after 3AM on January 19th, 2038.

So, what does that integer you have represent and relative to what start date/time?

Once you figure that out, it's easy to convert that to a .NET Date/Time, just by creating a date/time instance representing your integers start date/time and adding the number of seconds or whatever that integer represents to it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900