列内の各日付を増分する際の問題こんにちは、
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 ずつ増やす正しい方法は何でしょうか? ありがとうございます!
自動化とスクリプトRe: 列内の各日付を増分する際の問題ミリ秒が必要ない場合は、SQL クエリを変更して、そこからミリ秒を削除してみるといいと思います。
解決策として、減算部分までスクリプトが期待どおりに動作するか試しましたか? 列は数値、連続、適切な形式に変更され、JMP はそれらを日付として認識していますか (形式を Best に変更すると、JMP の datenum 形式になりますか)。
Re: 列内の各日付を増分する際の問題ご意見ありがとうございます。解決しました。日付増分関数には数値が必要なので、処理前にタイムスタンプを正しいデータ型に変換する必要がありました。また、「時間」を「秒」に変更する必要がありました。将来誰かがこれに遭遇した場合に備えて、これが動作するコードです。
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.")
);