web stats
converting current date time to datetime format for SQL Server 14 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2018, 12:59 PM
Kevin Carlin Kevin Carlin is offline
Mirth Newb
 
Join Date: Mar 2012
Posts: 23
Kevin Carlin is on a distinguished road
Default 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...
Reply With Quote
  #2  
Old 03-21-2018, 01:39 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,008
agermano is on a distinguished road
Default

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?
Reply With Quote
  #3  
Old 03-21-2018, 01:55 PM
Kevin Carlin Kevin Carlin is offline
Mirth Newb
 
Join Date: Mar 2012
Posts: 23
Kevin Carlin is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 04-08-2019, 10:31 AM
lbittle lbittle is offline
Mirth Newb
 
Join Date: Sep 2018
Posts: 21
lbittle is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:38 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation