none
current_timestamp? RRS feed

  • Question

  • Is there a way to use the SQL variable CURRENT_TIMESTAMP in the context of Linq to SQL?  Seems like a longshot, but I thought I'd ask.  There are benefits to using the current time on the DB server (simplifies time zone issues and reduces vulnerability to system clocks being out of sync).  I realize I can just make the extra round trip to query the DB server and then plug the value I found there, but it would be cleaner/cooler if something like the following worked:

     

    // magic will resolve this to CURRENT_TIMESTAMP in the generated SQL

    myEntity.last_modified_timestamp = myDataContext.CurrentTimestamp;

     

    Hopefully it make sense why I'm asking for this.  To be clear, I understand that I can do the following:

     

    myEntity.last_modified_timestamp = DateTime.Now;

     

    But that is the client time and I want the time on the DB server.

     

    I guess a trigger is a decent solution in some cases, but I'd rather not go there.

    Tuesday, March 25, 2008 10:18 PM

Answers

  • An option would be to provide INSERT and UPDATE stored procedures for this particular table that set last_modified_timestamp to GETDATE() on the server.

     

    [)amien

    Wednesday, May 28, 2008 6:51 PM
    Moderator