datetime

Difference between dates in SQLDF in R

本小妞迷上赌 提交于 2021-02-08 07:37:03
问题 I am using the R package SQLDF and am having trouble finding the number of days between two date time variables. The variables ledger_entry_created_at and created_at are Unix Epochs and when I try to subtract them after casting to julianday , I return a vector of NA 's. I've taken a look at this previous question and didn't find it useful since my answer to be given in SQL for reasons that are outside the scope of this question. If anyone could help me figure out a way to do this inside SQLDF

OpenERP/Odoo: fields.datetime.now() show the date of the latest restart

懵懂的女人 提交于 2021-02-08 06:52:50
问题 I have a field datetime. This field should have by default the datetime of "now", the current time. However, the default date is the time of the lastest restart . Please find below my code: 'date_action': fields.datetime('Date current action', required=False, readonly=False, select=True), _defaults = { 'date_action': fields.datetime.now(), 回答1: You are setting the default value of date_action as the value returned by fields.datetime.now() , that is executed when odoo server is started. You

Using “tzwhere” module in Python 3

微笑、不失礼 提交于 2021-02-08 06:51:22
问题 I am trying to use the tzwhere module in Python 3. I want to enter in the coordinates of a location and return the timezone. However, when I run the following code: !pip install pytz !pip install tzwhere import pytz from tzwhere import tzwhere tzwhere = tzwhere.tzwhere() timezone_str = tzwhere.tzNameAt(37.3880961, -5.9823299) print(timezone_str) #Europe/Madrid I get this error: FileNotFoundError: [Errno 2] No such file or directory: '/Users/s.rayan/anaconda/lib/python3.6/site-packages/tzwhere

JavaScript: Weeks per year

自作多情 提交于 2021-02-08 06:44:27
问题 In javascript, how can I find out how many weeks a given year has? Getting the weeknumber from year-dec-31 will fail since that can result in week 1. This question calculate number of weeks in a given year sort of answers it, but is there any neat way of calculating this in JS? 回答1: For the ISO 8601 Standard Weeks function getISOWeeks(y) { var d, isLeap; d = new Date(y, 0, 1); isLeap = new Date(y, 1, 29).getMonth() === 1; //check for a Jan 1 that's a Thursday or a leap year that has a /

Difference between dates, rounded result to nearest minute

落爺英雄遲暮 提交于 2021-02-08 06:33:13
问题 The difference between dates wants to round to the nearest minute. Round date1 , date2 down or up. The returned result is already rounded up to the full minute. I can modify date1 , date2 . Do not modify the result already returned date2- date1 Code here: https://stackblitz.com/edit/react-azau4g Example: First step this.state = { date1: "2019-06-29 21:25:38+00", date2: "2019-06-29T21:25:40.000+00:00" } round = (item) => { var m = moment(item); var roundUp = (m.second() || m.millisecond() ? m

Pandas Dataframe: Fill Missing Months

匆匆过客 提交于 2021-02-08 05:33:42
问题 I've seen this done with the Panda Timeseries, but was hoping to get some help with Dataframes. I have a file of monthly values from 1966-2009. I do not have data for the year 1985 and would like to add data for 2010/2011 as well. These additions would simply have NaNs attached to them. With the code below, I'm trying to cut my dataset so that it starts at 1980 and then add in the years that are missing with NaN values attached. However, nothing gets cut and nothing is added. Is there

Convert ms into a string date with Java 8

Deadly 提交于 2021-02-08 05:25:34
问题 I have a timestamp as ms and format this with a SimpleDateFormater like this: SimpleDateFormat sdfDate = new SimpleDateFormat("MM/d/yyyy h:mm a"); return sdfDate.format(new Date(timeStamp)); Now I'd like to change this to use the new Java 8 abilities. Seems like I really can't find a way to get this working with the new Java 8 Classes. Anyone got a hint? 回答1: If all you have is a millisecond value (assuming from the Unix Epoch) you can get an LocalDateTime using something like: LocalDateTime

Converting an array datatime.datetime to float

牧云@^-^@ 提交于 2021-02-08 05:23:31
问题 Is it possible to convert something like this; array([datetime.datetime(2014, 2, 1, 0, 0, 0, 100000), datetime.datetime(2014, 2, 1, 0, 0, 0, 300000), datetime.datetime(2014, 2, 1, 0, 0, 0, 500000), ..., datetime.datetime(2014, 2, 1, 19, 30, 0, 500000), datetime.datetime(2014, 2, 1, 19, 30, 0, 700000), datetime.datetime(2014, 2, 1, 19, 30, 0, 900000)], dtype=object) to this: array([ 1.39277301e+09, 1.39277301e+09, 1.39277301e+09, ..., 1.39285442e+09, 1.39285442e+09, 1.39285442e+09]) I would

Converting a Dask column into new Dask column of type datetime

这一生的挚爱 提交于 2021-02-08 04:29:10
问题 I have an unparsed column in a dask dataframe (df) that I am using pandas to convert to datetime and put into a new column in the dask dataframe. However it breaks as column assignment doesn't support type DatetimeIndex. df['New Column'] = pd.to_datetime(np.array(df.index.values), format='%Y/%m/%d %H:%M') 回答1: this should work import dask.dataframe as dd # note df is a dask dataframe df['New Column'] = dd.to_datetime(df.index, format='%Y/%m/%d %H:%M') 来源: https://stackoverflow.com/questions

Pass a datetime object to url in django

懵懂的女人 提交于 2021-02-08 03:59:30
问题 How can I pass a datetime e.g. datetime.date(2017, 12, 31) object to a url in django? My template: {% for key, value in my_dictionary.items %} {{ key.0 }} # it displays Dec. 31, 2017 ... {% endfor %} Passing it to the url as: href="{% url 'my_url:my_date' selected_day=key.0 %}"> My urls.py: url(r'^my-date/(?P<selected_day>\w+)/$', name='my_date') Error: Exception Type: NoReverseMatch Exception Value: Reverse for 'my_date' with keyword arguments '{'selected_day': datetime.date(2017, 12, 31),}