date

How do I calculate the average difference between two dates in Django?

给你一囗甜甜゛ 提交于 2021-01-28 12:22:37
问题 Using Django and Python 3.7. I'm tryhing to write a query to give me the average of the difference between two dates. I have two fields in my model, both "DateTimeField"s, and I try to calculate the average difference like so everything_avg = Article.objects.aggregate( avg_score=Avg(F('removed_date') - F('created_on'), output_field=models.DateTimeField()) ).filter(removed_date__isnull=False) return everything_avg but I end up getting this error when running the above AttributeError: 'dict'

Merge 2 Pandas dataframes by dates within a few days of each other?

你离开我真会死。 提交于 2021-01-28 12:22:13
问题 I have these two pandas dataframes I created and cleaned from online data, and I was trying to merge them based on their dates, which are all by month. However, the first dataset has its days on the last day of the month, whether the second dataset is based on the first day of the month. # data1 0 1987-01-01 63.752 1 1987-02-01 64.152 2 1987-03-01 64.488 3 1987-04-01 64.995 # data2 0 1987-01-31 1115.10 1 1987-02-30 1095.63 2 1987-03-30 1036.19 3 1987-04-30 1057.08 I would normally merge them

Spring Boot Date conversion from Form

喜欢而已 提交于 2021-01-28 11:57:37
问题 I'm having a few issues with getting a date from a controller because I don't understand what's the right format for it to work. Controller: @RequestMapping(value = "/findFlights", method = RequestMethod.POST) public String findFlights(@RequestParam("from") String from, @RequestParam("to") String to, @RequestParam("departureDate") @DateTimeFormat(pattern = "YYYY-MM-DD") LocalDate departureDate, Model model) {} Form: <form th:action="@{/findFlights}" method="POST"> From:<input type="text" name

Check if the time is within the min and max range

妖精的绣舞 提交于 2021-01-28 11:50:39
问题 I don't know what's happening here: I need to return true if the current time is between a given range, ex: now is 15:45:00 and is between 12:00:00(min) and 18:00:00(max), but this method is doing it wrong: private boolean verifyIfInside(String max, String min){ try { DateFormat dateFormat = new SimpleDateFormat ("HH:mm:ss"); Date date = new Date(); String hour1 = min; String hour2 = max; String newHour = dateFormat.format(date); Date minHour, maxHour, nowHour; minHour = dateFormat.parse

How to get correct output of hour: “2-digit” for toLocaleString(“en-US”) with AM/PM?

自古美人都是妖i 提交于 2021-01-28 11:50:17
问题 According to the toLocaleString() MDN Documentation the option hour: "2-digit" should return a 2 digit representation of the hour, but it returns only 1 digit if the locale is en-US and the format is AM/PM . (Update: AM/PM mention) let d = new Date("2019-05-03 15:00:00").toLocaleString("en-US", {hour: "2-digit", minute: "2-digit"}); console.log(d); Is there a workaround or another easy way to get the 2-digit hour for the US locale, displaying the AM and PM? 回答1: You just have to explicitly

How to format columns dates in python that they are weekly based on eachother?

巧了我就是萌 提交于 2021-01-28 11:25:18
问题 I have a dataframe df that looks similar to this: identity Start End week E 6/18/2020 7/2/2020 1 E 6/18/2020 7/2/2020 2 2D 7/18/2020 8/1/2020 1 2D 7/18/2020 8/1/2020 2 A1 9/6/2020 9/20/2020 1 A1 9/6/2020 9/20/2020 2 The problem is that when I extracted the data I only had Start date and End date for every identity it replaced, but I have the data by weeks all identitys have the same amount of weeks some times all identitys can have 5 or 6 weeks but they are always the same. I want to make

Getting negative value in date.gettime()

风格不统一 提交于 2021-01-28 09:19:21
问题 Facing an issue where I am trying to parse a string value into date and when I try to do date.getTime() I am getting negative value. This is the string I am parsing "01:00:07". and this is the value in date object I get "Thu Jan 01 01:00:07 GMT+05:30 1970". Still in getTime() I am getting negative value "-16193000" Code for achieving this : long sum = 0; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");// I have also tried "HH:mm:ss" format. it gives same result Date date

JavaScript Date.prototype.toISOString() loses offset [duplicate]

痞子三分冷 提交于 2021-01-28 09:12:01
问题 This question already has answers here : How to ISO 8601 format a Date with Timezone Offset in JavaScript? (11 answers) Closed 5 years ago . Why does this method use UTC timezone ( Z ) and not include the local time offset ( +/-HH:SS ) instead? The "ISO" in the method name refers to ISO 8601—which allows for "time zone designations" to be expressed as part of its format. In other words, new Date() tells me both the date and time, and the timezone offset (via getTimezoneOffset() ). But

PowerShell date format mmddyy

偶尔善良 提交于 2021-01-28 09:08:47
问题 I know I can set a date to a variable in PowerShell using $a = Get-Date It works great, but when looking through the documentation on formatting the date, there wasn't one for MMDDYY . How do I accomplish this? 回答1: Because $a is effectively a System.DateTime. You can do: $a = Get-Date Write-Host $a.ToString('MMddyy') Full details on custom Date and Time Format Strings are in Custom Date and Time Format Strings . 回答2: You just have to get creative with the -UFormat options. To get exactly

Laravel : How put a date from order placed

陌路散爱 提交于 2021-01-28 09:06:33
问题 I'm trying to put the date order placed using Carbon. my-order.blade.php @foreach ($order->products as $product) <div>{{ presentDate($order->created_at) }}</div> <div>Total : {{ $product->price }} €</div> <div>Quantity: {{ $product->pivot->quantity }}</div> </div> OrderProduct.php use Carbon\Carbon; function presentDate($date) { return Carbon::parse($date)->format('M d, Y'); } Maybe I have to put the function in another place ? Thanks for your help. 回答1: You can leverage Laravel Accessors &