Date conversion

  • Thread starter Thread starter Piotr Karwatka
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top