增加列中每個日期的問題你好,
我正在從 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 的日期數字格式)。
回覆:增加列中每個日期的問題感謝您的輸入。明白了。日期增量函數需要一個數值,因此在處理之前必須將時間戳記轉換為正確的資料類型。我還必須將“小時”更改為“秒”。如果將來有人遇到此問題,這裡是工作代碼。
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.")
);