Date conversion

P

Piotr Karwatka

Hi!

I have a little problem - i have an integer value with contain a number of
some day in current day (for example 56) - and my problem is - how can i
caonvert this integer value to DateTime (for example 33 = 02.02.2004)? I
want to reverse function to DateTime.DaysOfYear

Thanks
 
S

Shiva

May be like this?

// C#
DateTime x = new DateTime (DateTime.Now.Year, 1, 1);
x = x.AddDays (<your day count>-1);
// x now holds DateTime for <your day count>

Hi!

I have a little problem - i have an integer value with contain a number of
some day in current day (for example 56) - and my problem is - how can i
caonvert this integer value to DateTime (for example 33 = 02.02.2004)? I
want to reverse function to DateTime.DaysOfYear

Thanks
 
H

Hans Kesting

Piotr said:
Hi!

I have a little problem - i have an integer value with contain a
number of some day in current day (for example 56) - and my problem
is - how can i caonvert this integer value to DateTime (for example
33 = 02.02.2004)? I want to reverse function to DateTime.DaysOfYear

Thanks

How about this
- start with jan 1st of your year
- add (number-1) days

public DateTime ReverseDaysOfYear(int year, int days)
{
DateTime dt = new DateTime(year, 1, 1);
dt = dt.AddDays(days-1);
return dt;
}


Hans Kesting
 
E

Eliyahu Goldin

Time interval is represenred by TimeSpan structure. You can create a
timespan for the number of days you need and than add it to an instance of
DateTime structure preset to to the beginning of the year.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top