增加列中每个日期的问题你好,
我正在从 SQLite 文件导入带有时间戳的数据,下面是一个时间戳示例:2024-04-12T18:55:42.464558Z。由于 JMP 不支持微秒,我修剪了最后 8 个字符并将列转换为时间格式。到目前为止一切似乎都正常。但是,当我尝试将每个时间戳增加 6 小时(时区差异)时,所有时间戳都会被删除。
dt = Current Data Table(); // Gets the currently active data table
// Check if the "timestamp" column exists
If( Contains( dt << Get Column Names("String"), "timestamp"),
// Get the column reference
col = Column(dt, "timestamp");
// Truncate the last 8 characters from each value in the "timestamp" column
col << Set Each Value( Substr( Char( col ), 1, Length( Char( col ) ) - 8 ) );
// Convert the truncated timestamps to numeric datetime values
col << data type(numeric) << modeling type(continuous) << format("yyyy-mm-ddThh:mm:ss");
// Subtract 6 hours from each datetime value using Date Increment
For( i = 1, i <= N Rows(dt), i++,
If( !Is Missing( col[i] ),
col[i] = Date Increment( col[i], "Hour", -6 );
);
);
Show("Timestamps have been truncated and decremented by 6 hours.");
,
// Error handling if column does not exist
Show("Error: 'timestamp' column does not exist in the current data table.")
);将时间戳转换为 JMP 可接受的格式并将每个值增加 -6 的正确方法是什么?谢谢!
自动化和脚本回复:列中每个日期递增的问题如果您不想有毫秒,我认为您可以尝试修改您的 SQL 查询并在那里删除它们。
对于您的解决方案,您是否尝试过让脚本按照您的预期执行操作,直到减法部分?列是否更改为数字、连续、格式正确,并且 JMP 将它们识别为日期(将格式更改为最佳,您是否获得 JMP 的 datenum 格式)。
回复:列中每个日期递增的问题感谢您的意见。我搞明白了。日期增量函数需要一个数值,因此在处理之前必须将时间戳转换为正确的数据类型。我还必须将“小时”更改为“秒”。如果将来有人遇到这种情况,这是有效的代码。
dt = Current Data Table(); // Gets the currently active data table
// Check if the "timestamp" column exists
If( Contains( dt << Get Column Names("String"), "timestamp"),
// Get the column reference
col = Column(dt, "timestamp");
// Process each row and remove the last 8 characters from the timestamp string
col << Set Each Value( Substr( :timestamp, 1, Length( :timestamp ) - 8 ) );
Show("Timestamps have been truncated.");
col << data type(numeric) << modeling type(continuous) << format("yyyy-mm-ddThh:mm:ss");
// Loop through each row in the column
For( i = 1, i <= N Rows(dt), i++,
// Read the value in the "timestamp" column for row i
timestamp_value = col[i];
numeric_datetime = Num( timestamp_value, Informat( "yyyy-mm-ddThh:mm:ss" ) );
numeric_datetime_adjusted = Date Increment(numeric_datetime, "second", -21600);
col[i] = numeric_datetime_adjusted;
);
,
// Error handling if column does not exist
Show("Error: 'timestamp' column does not exist in the current data table.")
);