Syntax for Inserting Dates into External Database (SQL Server) Using Database Connector
Hello all, I am trying to insert date information into an external database using the Database Connector in a microflow. I have attached a screenshot of the sql statement that I am using (I’ve whited out my company name between “At” and the comma). I am encountering an error trying to insert date values. I am having no issues inserting integers (the ID attributes) and strings (the non-ID and non-date attributes) using the syntax below which was included in a YouTube video posted by Mendix, however the date values are causing issues claiming that the “+” operator is invalid. I understand the reason behind this and have tried using “&” as well (to no avail). I am wondering if there is a different methodology through which to insert date values into external databases, perhaps a different operator or some other workaround? There are multiple date selections in the app and we want them to be intuitive for the user and to have a consistent format (e.g. no typing out a string that represents a date – we want the date picker). I tried a workaround where I store the dates as strings in the external database, casting the dates that users input as strings and then casting the strings from the database as dates when retrieving them, but this ended up getting messy quickly and I know it’s bad practice so I figured I would be best to look here. Thanks for your help.
You need single quotes around the dates just like you are with your strings.
Hi! Ryan is right! You just have to put a single quote on each side: '+$DateInsert+'
But ... IMPORTANT ... first you have to convert $DateInsert to String