MongoDB database gives me the wrong time from input with type datetime-local - mongodb

When I write a date in my input I receive the wrong time in the database (2 hours earlier than the time I want), in the pictures you can see that I got the hour 5:21 in the database even though I wrote the time 7:21 in the input:
The time in the input:
The time in the database:
I thought that it is maybe because of the time zone (I am In Israel) and I try to use the Library Moment.
In this way:
holiday.beginDate = moment.tz(req.body.beginDate, "Asia/Jerusalem");
But, I get the same result.
Someone can tell me what I am doing wrong or what should I do to make the time I write in the input be the same time in the database?
Thank you.

Related

Get the average from a column with minutes and seconds on Tableau

This is a pretty straight up question. It may be simple, but I'm having a hard time solving it:
How can I get the average of time? I have a column on my dataset called response time which has the number of time a client waited before they got the answer from a company. The values on this column will never be greater than 00:50:00. I need to get the average response time by month but the field comes as a string. I tried creating a calculated field called avg_time by doing this:
DATETIME(AVG(FLOAT([response time])))
but all I got was:
An error occurred while communicating with the PostgreSQL data source 'database_name (namespace.database_name) (company)'
Error Code: A7B6E1FA
ERROR: invalid input syntax for type double precision: "00:09:03"
Can you guys help me with that, please? Thanks!

date time with timezone

The date/time strings we're sending over to pub/sub look like this:
2018-07-18T17:30:08Z
I created a data flow job to insert these into Big Query and it failed at insert.
Stripping out the "Z" at the end like this was successful:
2018-07-18T17:30:08
The problem is that Big Query seems to be interpreting this as a local time, and not UTC.
I've tried both of these ways to insert the time zone:
2018-07-18T17:30:08+00:00
2018-07-18T17:30:08+0000
Both are rejected.
What's the correct way to do this, or is there some other way I can force Big Query to interpret these times as UTC?

Saving date in MongoDB getting offset even when providing time

I'll start by saying I know there are many timezone-related questions and answers out there. Maybe I'm just missing an obvious one.
I'm trying to save a date range pair in Mongo - a from date and a to date. I'd like the from date saved at time 00:00:00:00 so if I run a query looking for >=2017-08-14 all results will show.
My problem is even though I'm sending a date with time 00:00:00.000Z Mongo is actually saving it -400, which appears to be equivalent to EDT offset right now. This leads to me either correcting a lot on the client side, or just showing and querying incorrect data. Once I get the date right, I'd like to just ignore time all together in my queries.
This is the range I'm sending to MongoDB
daterange: [ { from: 2017-08-14T00:00:00.000Z, to: 2017-08-31T00:00:00.000Z } ],
This is how that range is getting stored in Mongo
from: 2017-08-13 20:00:00.000,
to: 2017-08-30 20:00:00.000
What super silly rookie mistake am I making? Thanks for your help.
EDIT: It was a silly mistake. This post helped solve it. Query for a specific date with MongoDB and NodeJS
When I created the date with moment I Should've just done this:
moment(dateString).startOf('day')
It was a silly mistake. This post helped solve it. Query for a specific date with MongoDB and NodeJS
When I created the date with moment I should've just done this:
moment(dateString).startOf('day');

Rails date loss of precision

I have an annoying issue with Rails/Active Record and dates that I'm trying to figure out. We're using date fields for composite keys, which I am turning into timestamps to make it easier for use as URL parameters. This is working fine, but I have inconsistencies when trying to lookup records after converting the timestamp back into a DateTime. When the object is serialised, the ID sent back looks something like 1401810373.197,63 where the first number is the timestamp with milliseconds, and the second value is the original ID that rails normally uses.
When a request is received with this ID, the timestamp is parsed using the following
... get timestamp from input ...
Time.at(Rational(timestamp)).utc.strftime('%Y-%m-%d %H:%M:%S.%3N')
This works as expected, and the queries produced using this also work as expected. The issue lies in that the date time produced here, is slightly different to the one on the original object. They're out by something like 1ms which I'm assuming is due to the loss of precision when using to_f to get the timestamp.
I did a quick test in a console with the following code to replicate it
Model.all.each do |m|
puts Time.at(Rational("#{m.to_param.split(',').first}")).utc.strftime('%Y-%m-%d %H:%M:%S.%3N') == m.created_at.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')
end
The output of this shows multiple true and false values, so something is definitely going wrong in the conversion.
Currently, the to_param method simply converts the created_at field using to_f. I've tried changing this to "%.6f" % m.created_at.to_f but this hasn't changed anything.
Is there anything I can do to prevent this difference in times, as it's causing an array of issues.
This is currently running on Postgres, where the created_at column is a timestamp(3) column. We're using Rails 4.1 with jRuby 1.7.12
Ended up dropping the accuracy entirely. Now the database has a type of timestamp(0) and rails has been modified to not provide the milliseconds. Seems to be working :)

How to determine if a user has entered only date or also time in the form field?

I have a field where user can enter only date or also time in a text field. Now I know if I make 2 fields, one for date and one for time, I can check if the time field is empty or not.
What I'd like to do is have only one field. If user puts the ending date it takes time only, if user inputs date and time it takes both.
The problem I have is this: If user enters "8.12.2013" it in fact means "8.12.2013 0:0:0" where I convert it to Cdate. But then the end time is the first second of the date 8.12.2013 which means it 8.12.2013 means stop on that date (this is a stop time field). But in fact if a user writes 8.1.2013 it means roll till the end of the day.
Of course I can do date()>"8.12.2013" and it will work, but then if user enters date and time it will not work as it strips time part.
My question: Is there any function in ASP that would check if the time part of the date is set in a variable? I tried to use TIME but it shows 0 for hours, 0 for minutes and 0 for seconds even if the Cdate("8.12.2013") is used. I'd need the function to tell me that the time is not set so I could make a comparation using date() instead of now().
I hope that makes sense.
You could try something as simple as:
If CLng(myDate) = myDate Then ...
Dates are treated as time past a particular date etc., therefore integerising the date will remove the time.
-- EDIT --
Just to add to the above code: The CLng will convert a Date and Time into just a Date. By comparing this against the whole date you can see if any fractional part was included.
Please be aware that this would be considered bad practice in a strictly typed environment, such as .NET, but Classic ASP types are variants and are quite malleable.