Solved

Convert integer to datetime and back again

Posted on 2014-02-10
8
221 Views
Last Modified: 2014-02-11
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.

Thanks in advance
0
Comment
Question by:SweetingA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 39848463
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);

Open in new window


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

Expert Comment

by:john M
ID: 39848481
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 Comment

by:SweetingA
ID: 39848571
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 40
ID: 39848613
If you are only interested in the day part, then the following will do it:

a.Day / b
0
 

Author Comment

by:SweetingA
ID: 39848663
That would work is the difference between my two dates is always displayed in days, if that possible?
0
 

Author Comment

by:SweetingA
ID: 39848668
Actually it works well but how do i get the answer as a decimal?
0
 
LVL 10

Expert Comment

by:John Claes
ID: 39850712
you can make b a decimal to start with;
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39850786
a.Day / b - cint(a.Day / b)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question