0

I have a big list of different DateTime field. Then need converting date by specified range, for instance (this condition):

var startDate = new DateTime(2021, 2, 1, 0, 00, 00, DateTimeKind.Utc);
var endDate = new DateTime(2021, 5, 1, 0, 0, 00, DateTimeKind.Utc);

Then I added offset to my dateTime

    ...
var offset = dateTime!.Value.Subtract(firstCandleTimestamp);
return candles.Select(mc => { mc.Timestamp = mc.Timestamp.Add(offset); return mc; });
    ...

But i have some important property periodSeond to that convert my date. For example i converting my date to range by condition upper

  • {Timestamp: 01/02/2021 12:00:00 am}
  • {Timestamp: 01/02/2021 1:00:00 am}
  • {Timestamp: 01/02/2021 2:00:00 am}

But I need change my date and return by period. For exmaple periodSecond = 180 sec (= 3min)

  • {Timestamp: 01/02/2021 12:03:00 am}
  • {Timestamp: 01/02/2021 1:06:00 am}
  • {Timestamp: 01/02/2021 2:09:00 am}

or periodSeond = 86400( = 1day)

  • {Timestamp: 01/02/2021 00:00:00 am}
  • {Timestamp: 02/02/2021 00:00:00 am}
  • {Timestamp: 03/02/2021 00:00:00 am}

etc... Need change datetime by this scenario.

Romazes88
  • 29
  • 5
  • For rounding DateTime check this [answer](https://stackoverflow.com/questions/766626/is-there-a-better-way-in-c-sharp-to-round-a-datetime-to-the-nearest-5-seconds) – Genusatplay Mar 09 '21 at 20:46
  • Why does 180 second get added to first Timestamp, but 86400 second does not get added to first Timestamp? – NetMage Mar 09 '21 at 21:45
  • @NetMage because I need do different scenario, it is so exmaple. I need add various time (1m, 3, 5m, 60m, 1h, 1d, 1week, ...). – Romazes88 Mar 10 '21 at 08:06
  • That doesn't answer my question. Your example is inconsistent. You don't treat 1 day the same as 3 min. – NetMage Mar 10 '21 at 18:29
  • @NetMage I'll want to change dateTime by specified period, if set 3 min - period, need change every date +3 min to each. – Romazes88 Mar 11 '21 at 17:17

0 Answers0