On Tuesday, 1 November 2022 at 11:54:59 UTC, snosniv wrote:
I'm reading a csv file with date & time in one cell, however, the source file format doesn't seem to be constant, I sometimes get the following alternatives:
01/11/2022 11:00:27
and sometimes:
01 November 2022 11:00:27
So how to scan to ensure I get the seconds since epoch, using some way to detect the format with a switch or if statement??
TIAMy script did work, now failing miserably. I tried pasting some of the lines directly into tcl shell & now get this, which is really confusing me!
( I haven't shown the file read, split, etc to get the data rows from the CSV file).
(FIT_FILE_READ) 13 % puts $row
"1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,60.8,54.4,125.0,6.6,19.2,1658.0,64.0,--
(FIT_FILE_READ) 14 %
(FIT_FILE_READ) 14 % set row_data [split $row ","]
{"1 November 2022 11:00:27"} 156.0 24.2 15.7 131.6 13.6 7.0 60.8 54.4 125.0 6.6 19.2 1658.0 64.0 --
(FIT_FILE_READ) 15 %
(FIT_FILE_READ) 15 % set my_DateTime [lindex $row_data 0]
"1 November 2022 11:00:27"
(FIT_FILE_READ) 16 % set my_tcl_time [clock scan $my_DateTime -format "%d %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 17 % set my_tcl_time [clock scan $my_DateTime -format "%d %M %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 18 % set my_tcl_time [clock scan $my_DateTime -format "%D %M %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 19 % set my_tcl_time [clock scan $my_DateTime -format "%D %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 20 %
(FIT_FILE_READ) 20 % set my_tcl_time [clock scan $my_DateTime -format "%d %m %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 21 %
(FIT_FILE_READ) 21 % set my_tcl_time [clock scan $my_DateTime -format "%d %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 22 % puts $my_DateTime
"1 November 2022 11:00:27"
(FIT_FILE_READ) 23 %
I'm reading a csv file with date & time in one cell, however, the source file format doesn't seem to be constant, I sometimes get the following alternatives:
01/11/2022 11:00:27
and sometimes:
01 November 2022 11:00:27
So how to scan to ensure I get the seconds since epoch, using some way to detect the format with a switch or if statement??
TIA
My script did work, now failing miserably. I tried pasting some of the lines directly into tcl shell & now get this, which is really confusing me!
( I haven't shown the file read, split, etc to get the data rows from the CSV file).
(FIT_FILE_READ) 13 % puts $row
"1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,60.8,54.4,125.0,6.6,19.2,1658.0,64.0,--
(FIT_FILE_READ) 14 %
(FIT_FILE_READ) 14 % set row_data [split $row ","]
{"1 November 2022 11:00:27"} 156.0 24.2 15.7 131.6 13.6 7.0 60.8 54.4 125.0 6.6 19.2 1658.0 64.0 --
(FIT_FILE_READ) 16 % set my_tcl_time [clock scan $my_DateTime -format "%d %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 17 % set my_tcl_time [clock scan $my_DateTime -format "%d %M %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 18 % set my_tcl_time [clock scan $my_DateTime -format "%D %M %Y %H:%M:%S"]
input string does not match supplied format
On Tuesday, 1 November 2022 at 12:21:36 UTC, snosniv wrote:
On Tuesday, 1 November 2022 at 11:54:59 UTC, snosniv wrote:
I'm reading a csv file with date & time in one cell, however, the source file format doesn't seem to be constant, I sometimes get the following alternatives:My script did work, now failing miserably. I tried pasting some of the lines directly into tcl shell & now get this, which is really confusing me!
01/11/2022 11:00:27
and sometimes:
01 November 2022 11:00:27
So how to scan to ensure I get the seconds since epoch, using some way to detect the format with a switch or if statement??
TIA
( I haven't shown the file read, split, etc to get the data rows from the CSV file).
(FIT_FILE_READ) 13 % puts $row
"1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,60.8,54.4,125.0,6.6,19.2,1658.0,64.0,--
(FIT_FILE_READ) 14 %
(FIT_FILE_READ) 14 % set row_data [split $row ","]
{"1 November 2022 11:00:27"} 156.0 24.2 15.7 131.6 13.6 7.0 60.8 54.4 125.0 6.6 19.2 1658.0 64.0 --
(FIT_FILE_READ) 15 %
(FIT_FILE_READ) 15 % set my_DateTime [lindex $row_data 0]
"1 November 2022 11:00:27"
(FIT_FILE_READ) 16 % set my_tcl_time [clock scan $my_DateTime -format "%d %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 17 % set my_tcl_time [clock scan $my_DateTime -format "%d %M %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 18 % set my_tcl_time [clock scan $my_DateTime -format "%D %M %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 19 % set my_tcl_time [clock scan $my_DateTime -format "%D %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 20 %
(FIT_FILE_READ) 20 % set my_tcl_time [clock scan $my_DateTime -format "%d %m %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 21 %
(FIT_FILE_READ) 21 % set my_tcl_time [clock scan $my_DateTime -format "%d %B %Y %H:%M:%S"]
input string does not match supplied format
(FIT_FILE_READ) 22 % puts $my_DateTime
"1 November 2022 11:00:27"
(FIT_FILE_READ) 23 %
It looks like the DateTime with the quotes is causing the issue!
I didn't get these errors before, and nothing seems to have changed in the way the source CSV file gets saved, and script unchanged:
so I tried this:
(FIT_FILE_READ) 21 % puts $my_DateTime
"01 November 2022 11:00:27"
(FIT_FILE_READ) 23 % set s1 $my_DateTime
"01 November 2022 11:00:27"
(FIT_FILE_READ) 24 % set x1 [string length $s1]
27
(FIT_FILE_READ) 25 % set s2 [string range $s1 1 25] ; # strip out the quotes from start & end.
01 November 2022 11:00:27
(FIT_FILE_READ) 28 % set t1 [clock scan $s1 -format "%d %B %Y %H:%M:%S"] input string does not match supplied format
(FIT_FILE_READ) 29 % set t1 [clock scan $s2 -format "%d %B %Y %H:%M:%S"] 1667300427
Can someone explain what I'm doing wrong please, I seem to be constantly editing my script to solve what seems to be ever moving formats?
TIA, Niv.
I'm reading a csv file with date & time in one cell, however, the
source file format doesn't seem to be constant, I sometimes get the
following alternatives:
01/11/2022 11:00:27
and sometimes:
01 November 2022 11:00:27
So how to scan to ensure I get the seconds since epoch, using some
way to detect the format with a switch or if statement??
I'm reading a csv file with date & time in one cell, however, the source file format doesn't seem to be constant, I sometimes get the following alternatives:
01/11/2022 11:00:27
and sometimes:
01 November 2022 11:00:27
So how to scan to ensure I get the seconds since epoch, using some way to detect the format with a switch or if statement??
On 11/1/22 06:54, snosniv wrote:
I'm reading a csv file with date & time in one cell, however, the
source file format doesn't seem to be constant, I sometimes get the
following alternatives:
01/11/2022 11:00:27
and sometimes:
01 November 2022 11:00:27
So how to scan to ensure I get the seconds since epoch, using some
way to detect the format with a switch or if statement??
Normally, at least in the US, it is mm/dd/YYYY -- are you sure that:
"01/11/2022 11:00:27" is "01 November 2022 11:00:27"
and not:
"01/11/2022 11:00:27" is "11 January 2022 11:00:27"
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 716 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 56:57:11 |
| Calls: | 12,117 |
| Files: | 15,010 |
| Messages: | 6,518,672 |