Announcement

Collapse
No announcement yet.

converting current date time to datetime format for SQL Server 14

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • converting current date time to datetime format for SQL Server 14

    Mirth version 3.1.1.7461

    Having an issue with converting the current date time variable I'm using in to a datetime format that Sql Server 14 will accept.

    The code that I'm using is as follows:

    var insertDateTime1 = DateUtil.getCurrentDate("yyyyMMddHHmmss");
    var insertDateTime = DateUtil.getDate("yyyyMMddHHmm", insertDateTime1);

    The error I'm getting is as follows:

    DETAILS: Wrapped java.sql.SQLException: Conversion failed when converting date and/or time from character string.

    Is there a better way to get the current system date time or is there a better way to convert the insertDateTime to a "date time" format that is acceptable to sql server 14?

    Id appreciate any help that I can get...

  • #2
    If you're trying to get a current java.util.Date, you don't need to use DateUtil. Just do
    Code:
    var insertDateTime = new java.util.Date();
    But your error message looks like you are converting this to a string, which is then failing to convert back to a date.

    I think this should work to use as a string.
    Code:
    var insertDateTime = DateUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss");
    Though, you can also just call the sql function and insert GETDATE() instead of passing it a date.

    What does your insert code look like?

    Comment


    • #3
      The GETDATE() function in my Insert statement appears to solve the issue but its nice to get some other ways to solve the problem.

      For those who don't understand what I mean

      var MSHInsert=dbConn.executeUpdate("insert into (table name) (insertDateTime)values(GETDATE())

      My SQL query is much larger than this. This is just to show the field and the value entered into the DB.

      Thanks for your help.

      Comment


      • #4
        Posted a Mirth Minute Helper video on youtube for this issue, hope it helps. Please subscribe to our channel:

        https://youtu.be/BH0kIcRKAPs

        Or, go to the Mirth Connect User Group website:

        https://www.mcug.org in the Help Center section of the site.

        Nextgen also has some details on this topic:

        http://www.mirthcorp.com/community/w...ing+with+Dates

        Comment

        Working...
        X