Problemas al incrementar cada fecha en una columna.Hola,
Estoy importando datos con marcas de tiempo de un archivo SQLite, aquí hay una marca de tiempo como ejemplo: 2024-04-12T18:55:42.464558Z. Como JMP no admite microsegundos, estoy recortando los últimos 8 caracteres y convirtiendo la columna a un formato de hora. Todo parece funcionar hasta este punto. Sin embargo, cuando intento incrementar cada marca de tiempo en 6 horas (diferencias de zona horaria), todas las marcas de tiempo se eliminan simplemente.
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.")
);¿Cuál sería la forma correcta de convertir básicamente las marcas de tiempo a un formato que sea aceptable para JMP e incrementar cada valor en -6? ¡Gracias!
Automatización y secuencias de comandosRe: Problemas al incrementar cada fecha en una columnaSi no desea tener milisegundos, creo que podría intentar modificar su consulta SQL y eliminarlos allí.
Para su solución, ¿ha intentado que su script haga lo que espera que haga hasta la parte de resta? ¿Se cambiaron las columnas a numéricas, continuas, con el formato adecuado Y JMP las reconoce como fechas (cambie el formato a Mejor y obtendrá el formato datenum de JMP)?
Re: Problemas al incrementar cada fecha en una columnaGracias por tu contribución. Lo tengo resuelto. La función de incremento de fecha requiere un valor numérico, por lo que la marca de tiempo tuvo que convertirse al tipo de datos correcto antes del procesamiento. También tuve que cambiar "Hora" a "Segundo". Aquí está el código de trabajo por si alguien se encuentra con esto en el futuro.
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.")
);