I use in Database with type date. I wrote example in field 12.12.2012.
If execute request in DB example:
"Select date From Date" => I get 12.12.2012.
I get 12.12.2012.
I use node.js for send data on client and get 12.12.2012:00:00:00.
Mayby not properly entry in variable callback?
The date you received '12.12.2012:00:00:00' includes the time as well as the date. You can look at it in two parts where '12.12.2012' is the date, and '00:00:00' is the hours:minutes:seconds of the day. Read more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date.
Related
I'm trying to convert a date object to a Firestore timestamp.
var dateOBJ = new Date();
var timeStamp = new firebase.firestore.Timestamp(dateOBJ);
This gives me an error:
Uncaught Error: Timestamp seconds out of range: Sun Dec 09 2018 11:37:05 GMT+0100
I tried converting the date object to seconds first by using .getTime() / 1000, but it's still out of range.
The timestamp is gonna be the expiration date for an url, so I need to add some time to it.
There are two ways of setting a date field in Cloud Firestore:
You specify a Date value for the field, in which case you fully determine what date is written.
You specify the firebase.firestore.FieldValue.serverTimestamp(), in which case the server writes the current date.
There is no way in the API to combine these two options, you either use one or the other.
Since you comment that you want to store the timestamp and an offset, that is also what I'd store:
a timestamp field that you let the server populate with firebase.firestore.FieldValue.serverTimestamp().
a offset field, that you populate from the app with the offset in days/hours.
That way you can reconstitute the effective expiration timestamp by combining the two fields.
You could even add a third field that stores the expiration timestamp, but that will require an extra write operation. I'd typically do this in Cloud Functions, to ensure you keep full control over the field and clients can't spoof it. If you don't do it in Cloud Functions, consider writing security rules that validate that the value if the calculated field is indeed the result of that calculation.
You won't get a consistent server side timestamp with a JavaScript date. Instead, send the server timestamp from the SDK:
const timestamp = firebase.firestore.FieldValue.serverTimestamp()
If you still want to set the timestamp as a Date you can just pass new Date() to Firestore and it will be saved as a timestamp.
Frank is right about setting timestamps into firestore.
If you want to check that timestamp on the front end afterwards you need to use .toDate on the timestamp object returned from firestore to turn it back into a JS date.
I am saving the date to SQL database from nodejs. While saving the date to SQL I am getting error " parameter.value.getTime ".
While passing a date in this format while passing it to SQL.
2018-06-27T18:30:00.000Z
In early records in the database, DateTime format is this one.
2018-05-25 14:39:19.433
How can I solve this error? I already used moment js to use another format for saving the date but it is not working.
You should not try to change the format of your String, but convert it into JavaScript Date instead:
var yourDate = new Date(yourString);
I would like to know whether the following is the right method to handle datetime data type in WebApi 2, Javascript and database.
DateTime from Javascript to WebApi:
var date = new Date();
var datestring = date.toISOString();
//Send datestring to WebApi
DateTime from WebApi to Javascript:
//on getting datetime value from `http.get` call
var dateFromServer = new Date(dateFromServer);
WebApi:
Incoming date
do nothing simply store the datestring returned in database column with datatype datetime
Getting date from database and Returning date to client:
no datetime manipulation (simply return as per WebApi Json serializer ex: 2015-10-23T18:30:00). Client would automatically convert the UTC datetime to local datetime
Yes if you don't want to handle any information about user Timezone etc... this is an acceptable way.
Just make sure that any time you want a date produced from the server for a comparison or something else to use the c# DateTime.UtcNow
method.
I think Having a "Global UTC Convention" its a quite safe and good solution but it has some limits.
For example if you want to Alert all of your users located in different timezones at 09:00 am (on each user's country) then its impossible to know when its "09:00" for each one.
One way to solve this(and it's the one i prefer), is to store manually each user's timezone info separately on the database, and every time you want to make a comparison simply convert the time.
TimeZoneInfo.ConvertTimeFromUtc(time, this.userTimezone);
Alternatively if you want to store all timezone information on the server you can :
Send your date from javascript to the server using the following format :
"2014-02-01T09:28:56.321-10:00" ISO 8601 also supports time zones by replacing the Z with + or – value for the timezone offset.
Declare your WEB API 2 Date types with the "DateTimeOffset" type.
Finally store your dates within the database using the "datetimeoffset" type.
This way any time on the server or the database you have all the information about the user's time and timezone.
You will find this article useful
I want to query mongo collection by date. Example:
var startDate = new Date(dateNow.getUTCFullYear(),dateNow.getUTCMonth(),dateNow.getUTCDate(),dateNow.getUTCHours(),0);
var endDate = new Date(dateNow.getUTCFullYear(),dateNow.getUTCMonth(),dateNow.getUTCDate(),dateNow.getUTCHours()+1,0);
query.timeRegistered = { '$gte' : startDate, '$lt' : endDate };
... make mongo query ...
But it doesn't work. I assume that is because mongo saves date object in ISODate format. This query works from shell because there mongo converts Date to ISODate but from javascript (node.js) it doesn't work. I've tried all possible solutions but neither of them helped me.
Please, if anyone has any solution I would be very gratefull....
Please consider that by default the date operation in Mongo are in UTC, e.g. I entered the record in "t1" collection at June 22nd 2015 at 7:10 PM IST. however, in the shell you can see its value as 'ISODate("2015-06-22T13:40:08.545Z")' which is 5:30 hours behind. from your javascript code (which is run on the browser and hence take the browser timezone) try to create the start and end date variables as per the UTC timezone and then query the records. Let us know if it does't work, to keep it simple, give a very large date range and see if its working or not. as I am not a JS expert, I assume you may need to adjust your dates to make it in UTC.
however, tried with the Mongo client as below and it worked so I assume from JS also it should work as long you pass the date in right timezone.
db.t1.find({dt:{$gt:ISODate("2015-06-22T13:40:00.000Z"),$lt:ISODate("2015-06-22T13:41:00.000Z")} })
I am working with Javascript and for some requirement I need to connect oracle database and retrieve some data.
How can i read timestamp values from oracle database in java script please provide me the method or any help.
i have checked my database and the format Is "YYYY-MM-DD HH:MM:SS,fffffffff"
How can i read this time stamp value.
Thanks
Lr
you could use oracle's datetime conversion when you select the data TO_CHAR( datetime, format )
like this you can get the datetime as a string from you db in any format you want and don't need to change the format later in Javascript.
see Oracle Format Models
simple example:
SELECT TO_CHAR( SYSDATE, 'MM/DD/YYYY HH24:MM:SS' ) AS TS FROM DUAL
or if you want only the time without date:
SELECT TO_CHAR( SYSDATE, 'HH24:MM:SS' ) AS TS FROM DUAL
If in JavaScript you get a timestamp, then just use
new Date(timestamp)
Cannot be done through JavaScript.
You need a webservice that outputs the required data in a specific format (preferably JSON) and use AJAX (http://api.jquery.com/category/ajax/) to fetch it.