question

kauan pedroso avatar image
0 Likes"
kauan pedroso asked Jason Lightfoot commented

Change column type from int to Datetime

hey guys

I need some help, I have a table that the data comes from a SQL SERVE database but in the date columns the values are coming in seconds. How can I do to change this?

as is in FlexSim

1676657986117.png

as is in SQL SERVE

1676658475290.png



FlexSim 21.2.4
global tablesql querysql serve
1676657986117.png (3.0 KiB)
1676658475290.png (128.8 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot commented

It is possible to customize the table view to show the numeric value as a date time string - but you should ask the developers to add that as a standard formatting option for a table in the Ideas section.

In your select statement you can use for each field respectively the DateTime constructor to get the string value:

DateTime(InputTimestamp).toString() AS InputTimestamp

You can change how the string is formatted using a format string.

Note that once it's a string in FlexSIm and manipulates are harder so it's easier to work with the numeric value. For this reason I'd import the numeric value AND a formatted string into two columns for now:

SELECT InputTimestamp, DateTime(InputTimestamp).toString() AS InputDatetimeStr  FROM....
· 10
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

kauan pedroso avatar image kauan pedroso commented ·

So @Jason Lightfoot did what you had written but i ended up getting this error.

1676910322076.png


0 Likes 0 ·
1676910322076.png (2.7 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ kauan pedroso commented ·

Yes you have to use a function within FlexSim - so just import an empty string for InputDatetimeStr from SQLserver, and then run an update script (Table query with UPDATE sql) to set the empty string to the converted datetime using the InputDatetime field.

0 Likes 0 ·
kauan pedroso avatar image kauan pedroso commented ·

I'm trying to use the same function I use in sql serve, but I'm not able to add the column.


0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ kauan pedroso commented ·
FlexQL is closest to MySQL - it doesn't support that syntax.


You can just use:

SELECT InputTimestamp, '' AS InputTimestampStr FROM .......

when bringing in the data from SQL Server.

0 Likes 0 ·
kauan pedroso avatar image kauan pedroso Jason Lightfoot ♦♦ commented ·

Hello @Jason Lightfoot , I managed to create the empty columns as you said, if you can help me how I create the code to run an update script to define an empty string for the converted datetime using the inputDatetime field, thank you.

1677153246646.png

0 Likes 0 ·
1677153246646.png (14.9 KiB)
Show more comments