datetime

Rails datetime_select with time zone

拟墨画扇 提交于 2021-02-10 22:20:32
问题 I am writing a simple calendar app and having troubles with time zones. For as many nice Date and Time helpers, action view and active record sure don't play nice with time zones. I have an appointment model with the appointment_time attribute which is a datetime. My current issue is editing appointment_time with datetime_select within a form tag. <%= datetime_select :appointment_time, @appt.appt_time,ampm: true %> def appt_time appointment_time.in_time_zone(time_zone) #this is the

Group rows with that are less than 15 days apart and assign min/max date

馋奶兔 提交于 2021-02-10 20:42:08
问题 If the protocol_opening_date of different protocols are within 15 days of each other, i need to show them as one protocol in another column named expected start date. I don't know how to copy my table here as it looks but i'll try to explain as much as i can. So let's say if one protocol has the start_date of 24.01.2018 and end_date of 30.01.2018 and an other one has start_date of 25.01.2018 and end_date of 10.02.2018 I need to display them as a different protocol with a start_date of 24.01

Group rows with that are less than 15 days apart and assign min/max date

不羁的心 提交于 2021-02-10 20:38:40
问题 If the protocol_opening_date of different protocols are within 15 days of each other, i need to show them as one protocol in another column named expected start date. I don't know how to copy my table here as it looks but i'll try to explain as much as i can. So let's say if one protocol has the start_date of 24.01.2018 and end_date of 30.01.2018 and an other one has start_date of 25.01.2018 and end_date of 10.02.2018 I need to display them as a different protocol with a start_date of 24.01

When date only is required to save, Converting it to UTC and then to local may behave differently in different time zones

假如想象 提交于 2021-02-10 19:52:54
问题 I have a date field at front end. And I am saving it from a time zone say 19/04/2018 and I am on +8. When I load it on local datetime.ToLocalTime() works perfectly in +8 offset and it will show 19/04/2018 but a person sitting in +7 would get in 18/04/2018 23:00 and hence it will show 18/04/2018. How to handle this case. 回答1: In general: you should not convert date only to UTC, so you should keep it as local date. But it really depend on the use of data. If you are using for some

Strange behavior with pandas timestamp to posix conversion

谁说我不能喝 提交于 2021-02-10 18:41:49
问题 I do the following operations: Convert string datetime in pandas dataframe to python datetime via apply(strptime) Convert datetime to posix timestamp via .timestamp() method If I revert posix back to datetime with .fromtimestamp() I obtain different datetime It differs by 3 hours which is my timezone (I'm at UTC+3 now), so I suppose it is a kind of timezone issue. Also I understand that in apply it implicitly converts to pandas.Timestamp , but I don't understand the difference in this case.

Strange behavior with pandas timestamp to posix conversion

血红的双手。 提交于 2021-02-10 18:40:18
问题 I do the following operations: Convert string datetime in pandas dataframe to python datetime via apply(strptime) Convert datetime to posix timestamp via .timestamp() method If I revert posix back to datetime with .fromtimestamp() I obtain different datetime It differs by 3 hours which is my timezone (I'm at UTC+3 now), so I suppose it is a kind of timezone issue. Also I understand that in apply it implicitly converts to pandas.Timestamp , but I don't understand the difference in this case.

How do I efficiently apply pandas.Timestamp functions to a full dataframe/column?

一个人想着一个人 提交于 2021-02-10 18:22:03
问题 Pandas is a great tool for a number of data tasks. Many functions have been streamlined to efficiently be applied to columns rather than individual cells/rows. One such function is the to_datetime() function, which I use as an example later in this question. However, there are a number of commands in pandas that, as best I can tell from the documentation, do not directly relate to dataframes. The specific function I am interested in is the pandas.Timestamp.isocalendar() function, but there

How do I efficiently apply pandas.Timestamp functions to a full dataframe/column?

久未见 提交于 2021-02-10 18:20:53
问题 Pandas is a great tool for a number of data tasks. Many functions have been streamlined to efficiently be applied to columns rather than individual cells/rows. One such function is the to_datetime() function, which I use as an example later in this question. However, there are a number of commands in pandas that, as best I can tell from the documentation, do not directly relate to dataframes. The specific function I am interested in is the pandas.Timestamp.isocalendar() function, but there

Excel Datetime SN Conversion in Python

Deadly 提交于 2021-02-10 18:20:37
问题 My csv input file sometimes has excel serial numbers in the date field. I am using the following code as my input file should never contain dates prior to 01/2000. However, this solution is quite time consuming and I am hoping to find a better solution. Thank you. def DateCorrection(x): if pd.to_datetime(x) < pd.to_datetime('2000-01-01'): return pd.to_datetime(datetime.fromordinal(datetime(1900, 1, 1).toordinal() + int(x) - 2)) else: return pd.to_datetime(x) 回答1: Assuming your input looks

Select on value change

北城余情 提交于 2021-02-10 18:20:30
问题 I have a table that looks like this in a MySQL database: CREATE TABLE IF NOT EXISTS Example(Batch_Num int, Time DATETIME); INSERT INTO Example VALUES (1,'2020-12-04 05:06:12'), (1,'2020-12-04 05:06:13'), (1,'2020-12-04 05:06:14'), (2,'2020-12-04 05:06:20'), (2,'2020-12-04 05:07:12'), (2,'2020-12-04 05:07:20'), (1,'2020-12-04 05:07:25'), (1,'2020-12-04 05:07:35'), (3,'2020-12-04 05:07:35'); I would like to select all lines where the Batch_Num is different from the previous value including the