Php 以VARCHAR或seconds INT存储时间哪种方法最好?

Php 以VARCHAR或seconds INT存储时间哪种方法最好?,php,postgresql,date,datetime,time,Php,Postgresql,Date,Datetime,Time,我正在用从当地公交公司获得的GTFS数据构建一个项目,我正在使用PostgreSQL学习如何使用它。时间数据以HH:MM:SS(24小时)格式给出,但时间恰好超出了PostgreSQL的范围,如24:01:00,服务在前一天开始,并在第二天午夜后的夜间继续 我认为在VARCHAR字段中存储时间可以保留HH:MM:SS模式,并使用strotime()函数在PHP中转换它。我在这里读了一些关于*的文章,在这里我可以转换INT字段中的值。因此,我设想以这种方式存储时间,并通过编程将其转换回HH:MM:

我正在用从当地公交公司获得的GTFS数据构建一个项目,我正在使用PostgreSQL学习如何使用它。时间数据以
HH:MM:SS
(24小时)格式给出,但时间恰好超出了PostgreSQL的范围,如
24:01:00
,服务在前一天开始,并在第二天午夜后的夜间继续

我认为在
VARCHAR
字段中存储时间可以保留
HH:MM:SS
模式,并使用
strotime()
函数在PHP中转换它。我在这里读了一些关于*的文章,在这里我可以转换
INT
字段中的值。因此,我设想以这种方式存储时间,并通过编程将其转换回
HH:MM:SS
,但我感到困惑

由于pgSQL不接受24:00:00以外的任何内容,我是否应该将从CSV时间(格式为
HH:MM:SS
)接收的时间转换为
INT
?或者以字符串格式存储时间,并使用PHP的函数
strotime()
转换时间,这样我就可以按我想要的方式进行转换?如果人们同时使用我的应用程序,性能如何

致意


*我没有回应这条线,因为它已经快两年了


编辑:更好的解释和样本数据,5+1第一行

我想保留一个事实,那就是数据是关于时间的。巴士可能在今天晚上23:00左右开始行驶,明晚00:30结束服务。在GTFS数据中,这给出了24:3000,但PostgreSQL不认为是有效数据。 以下是数据:

calendar.txt

service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
B_2017-BW_A_J6-Samedi-03,0,0,0,0,0,1,0,20170304,20170527
B_2017-BW_A_J7-Dimanche-01,0,0,0,0,0,0,1,20170305,20170528
B_2017-BW_A_P2-Mercredi-06,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Mercredi-06-0010000,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Sem-N-3-06,1,1,0,1,1,0,0,20170306,20170601
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type
Baegd741,,"GEROMPONT Avenue des Déportés 74",,  50.651931,   4.890270,,,0
Baegd742,,"GEROMPONT Avenue des Déportés 74",,  50.651980,   4.890100,,,0
Baegegl1,,"AUTRE-EGLISE Eglise",,  50.663079,   4.923704,,,0
Baegegl2,,"AUTRE-EGLISE Eglise",,  50.663151,   4.923620,,,0
Baeggar1,,"AUTRE-EGLISE Gare",,  50.663857,   4.918398,,,0
route_id,service_id,trip_id,trip_short_name,direction_id,block_id,shape_id
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712028-B_2017-BW_A_P2-Mercredi-06,3,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712029-B_2017-BW_A_P2-Mercredi-06,9,0,3192088,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712030-B_2017-BW_A_P2-Mercredi-06,13,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712031-B_2017-BW_A_P2-Mercredi-06,21,0,3192092,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712032-B_2017-BW_A_P2-Mercredi-06,23,0,3192096,B00010001
calendar\u dates.txt

service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
B_2017-BW_A_J6-Samedi-03,0,0,0,0,0,1,0,20170304,20170527
B_2017-BW_A_J7-Dimanche-01,0,0,0,0,0,0,1,20170305,20170528
B_2017-BW_A_P2-Mercredi-06,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Mercredi-06-0010000,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Sem-N-3-06,1,1,0,1,1,0,0,20170306,20170601
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type
Baegd741,,"GEROMPONT Avenue des Déportés 74",,  50.651931,   4.890270,,,0
Baegd742,,"GEROMPONT Avenue des Déportés 74",,  50.651980,   4.890100,,,0
Baegegl1,,"AUTRE-EGLISE Eglise",,  50.663079,   4.923704,,,0
Baegegl2,,"AUTRE-EGLISE Eglise",,  50.663151,   4.923620,,,0
Baeggar1,,"AUTRE-EGLISE Gare",,  50.663857,   4.918398,,,0
route_id,service_id,trip_id,trip_short_name,direction_id,block_id,shape_id
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712028-B_2017-BW_A_P2-Mercredi-06,3,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712029-B_2017-BW_A_P2-Mercredi-06,9,0,3192088,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712030-B_2017-BW_A_P2-Mercredi-06,13,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712031-B_2017-BW_A_P2-Mercredi-06,21,0,3192092,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712032-B_2017-BW_A_P2-Mercredi-06,23,0,3192096,B00010001
routes.txt

service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
B_2017-BW_A_J6-Samedi-03,0,0,0,0,0,1,0,20170304,20170527
B_2017-BW_A_J7-Dimanche-01,0,0,0,0,0,0,1,20170305,20170528
B_2017-BW_A_P2-Mercredi-06,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Mercredi-06-0010000,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Sem-N-3-06,1,1,0,1,1,0,0,20170306,20170601
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type
Baegd741,,"GEROMPONT Avenue des Déportés 74",,  50.651931,   4.890270,,,0
Baegd742,,"GEROMPONT Avenue des Déportés 74",,  50.651980,   4.890100,,,0
Baegegl1,,"AUTRE-EGLISE Eglise",,  50.663079,   4.923704,,,0
Baegegl2,,"AUTRE-EGLISE Eglise",,  50.663151,   4.923620,,,0
Baeggar1,,"AUTRE-EGLISE Gare",,  50.663857,   4.918398,,,0
route_id,service_id,trip_id,trip_short_name,direction_id,block_id,shape_id
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712028-B_2017-BW_A_P2-Mercredi-06,3,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712029-B_2017-BW_A_P2-Mercredi-06,9,0,3192088,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712030-B_2017-BW_A_P2-Mercredi-06,13,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712031-B_2017-BW_A_P2-Mercredi-06,21,0,3192092,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712032-B_2017-BW_A_P2-Mercredi-06,23,0,3192096,B00010001
stop\u times.txt

trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type
12223270-C2017-choi-Sem-Cong-35,24:01:00,24:01:00,Csslesc2,37,0,0
12223270-C2017-choi-Sem-Cong-35,24:03:00,24:03:00,Csygare2,38,0,0
12223270-C2017-choi-Sem-Cong-35,24:05:00,24:05:00,Csycant2,39,0,0
12223270-C2017-choi-Sem-Cong-35,24:08:00,24:08:00,Csychap4,40,0,0
12223270-C2017-choi-Sem-Cong-35,24:08:00,24:08:00,Csyplac1,41,0,0
12223270-C2017-choi-Sem-Cong-35,24:09:00,24:09:00,Csychap2,42,0,0
12223270-C2017-choi-Sem-Cong-35,24:09:00,24:09:00,Csyjumo2,43,0,0
12223270-C2017-choi-Sem-Cong-35,24:11:00,24:11:00,Csysans2,44,0,0
12223270-C2017-choi-Sem-Cong-35,24:13:00,24:13:00,Csytouq2,45,0,0
12223270-C2017-choi-Sem-Cong-35,24:14:00,24:14:00,Csuptou2,46,0,0
12223270-C2017-choi-Sem-Cong-35,24:15:00,24:15:00,Csufrom6,47,0,0
12223270-C2017-choi-Sem-Cong-35,24:16:00,24:16:00,Crcrlf2,48,0,0
12223270-C2017-choi-Sem-Cong-35,24:17:00,24:17:00,Crccano2,49,0,0
12223270-C2017-choi-Sem-Cong-35,24:17:00,24:17:00,Crcrwas2,50,0,0
12223270-C2017-choi-Sem-Cong-35,24:18:00,24:18:00,Crchutt2,51,0,0
12223270-C2017-choi-Sem-Cong-35,24:19:00,24:19:00,Crcegli4,52,0,0
12223270-C2017-choi-Sem-Cong-35,24:19:00,24:19:00,Crcpcom2,53,0,0
12223270-C2017-choi-Sem-Cong-35,24:20:00,24:20:00,Crcplac4,54,0,0
12223270-C2017-choi-Sem-Cong-35,24:21:00,24:21:00,Crccamp2,55,0,0
12223270-C2017-choi-Sem-Cong-35,24:23:00,24:23:00,Crclorc2,56,0,0
12223270-C2017-choi-Sem-Cong-35,24:26:00,24:26:00,Ccycont2,57,0,0
12223270-C2017-choi-Sem-Cong-35,24:27:00,24:27:00,Ccychba2,58,0,0
12223270-C2017-choi-Sem-Cong-35,24:28:00,24:28:00,Crbrgar2,59,0,0
12223270-C2017-choi-Sem-Cong-35,24:29:00,24:29:00,Ccybeau2,60,0,0
12223270-C2017-choi-Sem-Cong-35,24:31:00,24:31:00,Ccychap2,61,0,0
12223270-C2017-choi-Sem-Cong-35,24:32:00,24:32:00,Ccygara2,62,0,0
12223270-C2017-choi-Sem-Cong-35,24:33:00,24:33:00,Ccybouc4,63,0,0
12223270-C2017-choi-Sem-Cong-35,24:33:00,24:33:00,Ccyfroi1,64,0,0
12223270-C2017-choi-Sem-Cong-35,24:34:00,24:34:00,Ccyga8,65,0,0
stops.txt

service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
B_2017-BW_A_J6-Samedi-03,0,0,0,0,0,1,0,20170304,20170527
B_2017-BW_A_J7-Dimanche-01,0,0,0,0,0,0,1,20170305,20170528
B_2017-BW_A_P2-Mercredi-06,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Mercredi-06-0010000,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Sem-N-3-06,1,1,0,1,1,0,0,20170306,20170601
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type
Baegd741,,"GEROMPONT Avenue des Déportés 74",,  50.651931,   4.890270,,,0
Baegd742,,"GEROMPONT Avenue des Déportés 74",,  50.651980,   4.890100,,,0
Baegegl1,,"AUTRE-EGLISE Eglise",,  50.663079,   4.923704,,,0
Baegegl2,,"AUTRE-EGLISE Eglise",,  50.663151,   4.923620,,,0
Baeggar1,,"AUTRE-EGLISE Gare",,  50.663857,   4.918398,,,0
route_id,service_id,trip_id,trip_short_name,direction_id,block_id,shape_id
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712028-B_2017-BW_A_P2-Mercredi-06,3,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712029-B_2017-BW_A_P2-Mercredi-06,9,0,3192088,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712030-B_2017-BW_A_P2-Mercredi-06,13,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712031-B_2017-BW_A_P2-Mercredi-06,21,0,3192092,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712032-B_2017-BW_A_P2-Mercredi-06,23,0,3192096,B00010001
trips.txt

service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
B_2017-BW_A_J6-Samedi-03,0,0,0,0,0,1,0,20170304,20170527
B_2017-BW_A_J7-Dimanche-01,0,0,0,0,0,0,1,20170305,20170528
B_2017-BW_A_P2-Mercredi-06,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Mercredi-06-0010000,0,0,1,0,0,0,0,20170308,20170531
B_2017-BW_A_P2-Sem-N-3-06,1,1,0,1,1,0,0,20170306,20170601
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
service_id,date,exception_type
B_2017-BW_A_J7-Dimanche-01,20170417,1
B_2017-BW_A_J7-Dimanche-01,20170501,1
B_2017-BW_A_J7-Dimanche-01,20170525,1
B_2017-BW_A_P2-Mercredi-06,20170405,2
B_2017-BW_A_P2-Mercredi-06,20170412,2
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type
Baegd741,,"GEROMPONT Avenue des Déportés 74",,  50.651931,   4.890270,,,0
Baegd742,,"GEROMPONT Avenue des Déportés 74",,  50.651980,   4.890100,,,0
Baegegl1,,"AUTRE-EGLISE Eglise",,  50.663079,   4.923704,,,0
Baegegl2,,"AUTRE-EGLISE Eglise",,  50.663151,   4.923620,,,0
Baeggar1,,"AUTRE-EGLISE Gare",,  50.663857,   4.918398,,,0
route_id,service_id,trip_id,trip_short_name,direction_id,block_id,shape_id
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712028-B_2017-BW_A_P2-Mercredi-06,3,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712029-B_2017-BW_A_P2-Mercredi-06,9,0,3192088,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712030-B_2017-BW_A_P2-Mercredi-06,13,0,3192097,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712031-B_2017-BW_A_P2-Mercredi-06,21,0,3192092,B00010001
B0001-12254,B_2017-BW_A_P2-Mercredi-06,12712032-B_2017-BW_A_P2-Mercredi-06,23,0,3192096,B00010001

在PostgreSQL中存储持续时间的最佳方法是使用


Duration(3小时)和time of day(3点钟)的格式类似(3:00),但它们的含义不同。

在PostgreSQL中存储Duration的最佳方法是使用


持续时间(3小时)和一天中的时间(3点)有相似的格式(3:00),但它们的含义不同。

我对日期数学有一个基本规则。不要这样做。总是让你知道是一致的其他包去做。喜欢你的数据库。PostgreSQL非常擅长日期数学

只需将时间存储为间隔,然后将其添加到零日期(今天、昨天等00:00:00时间)


我有一条约会数学的基本规则。不要这样做。总是让你知道是一致的其他包去做。喜欢你的数据库。PostgreSQL非常擅长日期数学

只需将时间存储为间隔,然后将其添加到零日期(今天、昨天等00:00:00时间)


这不是一个持续时间,我会在旅行期间使用它。我宁愿告诉你“那辆巴士16:37来,16:58到达你指定的目的地”。我只使用
interval
表示旅程所用的21分钟。@Krands:在这个例子中,您遗漏了一些对旅行至关重要的信息:日期。这并不是说巴士在16:37到达你的目的地在16:58,而是巴士在今天16:37到达你的目的地在16:58。我肯定没有选择好时间的例子,但我用所需的数据编辑了这个问题。这不是一个持续时间,我会在旅行的持续时间中使用它。我宁愿告诉你“那辆巴士16:37来,16:58到达你指定的目的地”。我只使用
interval
表示旅程所用的21分钟。@Krands:在这个例子中,您遗漏了一些对旅行至关重要的信息:日期。这并不是说巴士16:37到达你的目的地16:58,而是巴士今天16:37到达你的目的地16:58。我肯定没有选择好时间示例,但我用所需的数据编辑了问题。编辑你的问题,并包含一些示例数据。“巴士可能在[今晚]23:00左右开始行驶,明天早上00:30结束服务。”你能解释一下这对时间{23:00,24:30}与这对时间{23:00,00:30}的通信方式不同吗?或者它们对使用该系统的人有相同的意义吗?编辑你的问题,并包含一些样本数据。”公共汽车可能在晚上23:00左右开始行驶,明天早上00:30结束服务。“你能解释一下这对时间{23:00,24:30}是如何传达与这对时间{23:00,00:30}不同的信息的吗?或者它们对使用该系统的人来说有相同的意义吗?