Andrei Sebastian
Andrei Sebastian

Reputation: 67

Convert from DateTime to TimeStamp

I am trying to convert a DateTime variable to Timestamp. My variable has the current format : 1/23/17 2:14:31 PM and I would like it to be TimeStamp like so I can use it for Oracle SQL Developer. eg: 23-JAN-17 2.14.31.000000000 PM.

I have tried to convert it like this:

DateTime d = DateTime.Now.AddDays(-31);
Console.WriteLine(d.ToUniversalTime().ToString("O"));

but the output is nothing like TimeStamp:

2017-01-23T14:14:31.5838355Z

Upvotes: 0

Views: 10327

Answers (2)

Sombir Kumar
Sombir Kumar

Reputation: 1891

Try this:

DateTime d = DateTime.Now.AddDays(-31);
long epoch = (d.Ticks - 621355968000000000) / 10000000;
Console.WriteLine(d.ToUniversalTime().ToString("dd-MMM-yy HH:mm:ss") + ":" + epoch);

Upvotes: 1

Kostis
Kostis

Reputation: 963

Try this one

DateTime d = DateTime.Now.AddDays(-31);
Console.WriteLine(d.ToUniversalTime().ToString("hh-MMM-yy hh.mm.ss.ffffff tt"));

Upvotes: 0

Related Questions