1

I've been searching all over and cannot find a single solution that seems to do what I need, all of them are for a specific date and I need to dynamically subtract days only.

This is my current code:

DateTime.Now.AddDays(-30).ToString("M/d/yyyy");

The .ToString("M/d/yyyy"); part is what I'm currently using to convert to a human readable date. I need to get the DateTime into a unix format.

Any help or suggestions on this would be great, thanks!

Joe Scotto
  • 10,936
  • 14
  • 66
  • 136
  • 2
    In what way does http://stackoverflow.com/questions/249760 not answer your question? When you say all of the other solutions are "for a specific date" I doubt that they're really hard-coded to a particular date. Note that using `DateTime.Now` is a *really* bad idea here though... you almost certainly want `DateTime.UtcNow`. – Jon Skeet May 08 '17 at 15:50
  • 2
    How does [this answer](http://stackoverflow.com/a/250400/1141432) not help? – itsme86 May 08 '17 at 15:51
  • I'm not trying to convert a unix timestamp to datetime. I'm trying to convert a DateTime to unix timestamp. There has to be a simple way to just convert `Datetime.now` to a unix timestamp. – Joe Scotto May 08 '17 at 15:53
  • There is an answer in that thread linked by @itsme86 that converts a DateTime to a Unix timestamp. – Polyfun May 08 '17 at 15:58
  • http://stackoverflow.com/questions/17632584/how-to-get-the-unix-timestamp-in-c-sharp – KMoussa May 08 '17 at 16:08
  • And there's this one... https://codereview.stackexchange.com/questions/125275/converting-the-datetime-to-and-from-unix-epoch-times – Rufus L May 09 '17 at 03:03

0 Answers0