1

I'm using the jQuery FullCalendar control and populating a hidden field with the calendar events in a JSON string.

To accomplish this I have to convert the date/times.
The example function I found below passes them in a usable format.
However, it's adjusting the events based on the client time zone.

How do I modify the function below to convert a SQL datetime without adjusting for the client time zone?

I tried removing ToUniversalTime() as suggested on another post, but it throws the time WAY off.

private long ConvertToTimestamp(DateTime value)
{
   long epoch = (value.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
   return epoch;
}
TheAlbear
  • 5,507
  • 8
  • 51
  • 84
  • How are you communicating with SQL that it needs a `long`? Which flavor of SQL are you using? – Tim S. Jul 17 '12 at 21:07
  • possible duplicate of [How to convert UNIX timestamp to DateTime and vice versa?](http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa) – Tim S. Jul 17 '12 at 21:07

2 Answers2

0

I would try STRING newstring = String.Format("{0:yyyy-MM-dd HH:mm:ss}", yourdatevar); , and make sure the format is the one that you need for the SQL Datetime(I beleive that's it though).

DROP TABLE users
  • 1,955
  • 14
  • 26
0

Try the following which will format the date in to a long data time, this should stop any confusion with clients and different culture settings.

.ToString("yyyy-MM-dd HH:mm:ss:fff") 
TheAlbear
  • 5,507
  • 8
  • 51
  • 84