# Convert integer to datetime and back again

I would like to convert 28 to 28days in date time format (i.e. 28:00:00:00.0000000).

The reason is i have a timespan and i need to divide it by an integer and check if the result is a whole number.

###### Who is Participating?

PresidentCommented:
a.Day / b - cint(a.Day / b)
0

Independent ConsultantCommented:
Something like this:

``````DateTime firstOfTheMonth = new DateTime(2014, 2, 1);
DateTime twentyEighthOfTheMonth = new DateTime(2014, 2, 28);

TimeSpan twentyEightDays = new TimeSpan(twentyEighthOfTheMonth.ticks - firstOfTheMonth.ticks);
``````

I think that will work. Maybe usee 2014, 2, 29 for a full 28-days later?
0

Commented:
here is how to add days to a date
look and yoru see for months and years also
WHERE (DateAdd(Day, Datediff(Day,0, OnlinePayments.orderdate), 0) = @startdate) AND
if you looking for leap year
there  alot of code out there to test

hope this helps not sure if its what you want
0

Author Commented:
Sorry i don;t think i have explained myself too well.

a = 32:10:12:07.000000 (32days / 10hrs / 12 mins / 7 secs / 0 milli seconds) its a datetime
b = 28 its an integer

i need to divide a by b and then check if the number is a whole number, the problem at the moment is i have two different types datetime + integer and one will not divide by the other
0

PresidentCommented:
If you are only interested in the day part, then the following will do it:

a.Day / b
0

Author Commented:
That would work is the difference between my two dates is always displayed in days, if that possible?
0

Author Commented:
Actually it works well but how do i get the answer as a decimal?
0

Senior .Net Consultant & Technical AnalistCommented:
This ensures that the solution is a decimal to.

so 3 days divided by integer 2 is 1
and 3 days divided by decimal 2 is 1.5

hope to have helped
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.