Casting from Timestamp/String to Date - javascript

I need to insert to database two variables:
- "start" with value "9:00"
- "end" with value "20:00"
It can be types String or Timestamp, i would prefer the string. But in database table the fields are "Time" type. So how to cast it? I got only time values without full date like month, days and years.

From what I have read, if you want to insert a string into a MySQL TIME column, it will have to have the format HH:mm:ss. So the easiest solution for you might be to obtain your start and end times in the format of 09:00:00 and 20:00:00.
I expect the following INSERT statement to proceed without error:
INSERT INTO yourTable (`time_from`, `time_to`)
VALUES
('09:00:00', '20:00:00')
To be clear, I would recommend putting in a little effort in your code to obtain time data in this format. Then just insert it into MySQL without further hassle.

In a Date Field you van only Store Dates without time Information.
So you Must change the fieldtype or add a nee Field for this

Related

Moment.js to convert to correct timezone

I'm trying to convert my date to the correct time zone with moment.js. However, I always get the whole thing without a time specification.
Here is my program code:
console.log(von);
console.log(bis);
var nVon = moment.tz(von, "Europe/Berlin");
var nBis = moment.tz(bis, "Europe/Berlin");
console.log(nVon.format());
console.log(nBis.format());
This is what I see in the console:
2022-10-31T00:00:00+01:00
And here the original German format, which I want to save in the correct time zone in MongoDb.:
The problem is that it is saved in MongoDB with an hour loss of time like this, without UTC etc.: 2022-10-31T19:44:39.000+00:00
Date values in MongoDB are stored as UTC times - always and only!
If you need to preserve the client input time zone, then you must store it in a separate field. Usually the client takes responsibility to display the MongoDB UTC times as local times.
NB, you should never store date values as string, it's a design flaw. Store always proper Date objects. Thus store
moment.tz(von, "Europe/Berlin").toDate()

JavaScript AWSDate and AWSTime format to insert on db

I have two inputs, one of type date and one of type time.
The first one returns the date. For example, 2020-08-27
The second one returns the hour. For example, 23:04
I have two fields which are of type AWSDate and AWSTime:
date: AWSDate
time: AWSTime
I need to insert these into a mutation, how can I format these to ISO 8601?
I know with the date is with toISOString():
new Date('2020-08-27').toISOString(); // 2020-08-27T00:00:00.000Z
But for the hour of type AWSTime, what's the correct method? Thank you!
I hope I understand you correctly. You want a single ISOString from the individual date and time values.
new Date('2020-08-27 23:04').toISOString()

DynamoDB scan table with filter expression

I'm trying to scan a table and return all entries which match my filter expression. I've got an API Gateway which accepts a GET-Request that contains a starting time and a end time. (Format: [dd.mm.yyyy hh:mm:ss]
The database im scanning has an attribute called "timestamp" in the same format. I've tried it with the filter
Timestamp BETWEEN :date1 and :date2
date1 and date2 represent the starting and ending time from the API. Timestamp is the field in my Database.
Unfortunately the scan doesnt return any values.
Thanks a lot.
Your date format has to be in ISO 8601 string format for you to be able to scan on it. You can see this in the documentation here, under the "String" category.

Javascript Timestamp Conversion

the problem is as follows:
The file that i receive has a timestamp like
06/10/2016 02:58 AM
06/10/2016 05:20 PM
etc.
I'm using pentaho/kettle to eventually put this into a mysql database, the problem is that mysql only accepts yyyy-mm-dd hh-mm-ss timestamps. I'm not that great(if at all) in JavaScript and Kettle only support javascript, sadly.
I got it all split up, so it has a column called, 'days','months,'years', etc.
How can I make it so that if column Am/pm has "pm" in it, that it add 12 to the 'hours' column?
Or is there an easier way to do this in Kettle?
EDIT:
as i receive the csv i have 5 columns
1. Timestamp 2. Mobil_origin 3. mobile_Dest. 4.Call_cit 5.Call_dur
I want it so that all the timestamps get 'corrected' to the yyyy-mm-dd hh-mm-ss format.
so instead of 06/10/2016 05:20 PM it has to show 2016-10-06 17:20:00
It's the only thing that needs to happen actually, the rest of the file is good as is to be exported to mysql.

PHP function to match date

I am saving due date to db by varchar(50), date saved in db is 30-4-2015(due date), am using a filter to lists according to selected due date. How would I match the date? I believe that matching date varchar is not correct by simply using the query:
(select * FROM invoice WHERE id="10").
If you are saving a date you should look to use a Date column. If you need the word (due date) you could use a bit column on the table and flag it as 1 for example to say that this is a due date.
If you need to use a varchar some more clarification would be helpful.
Hope that helps

Categories

Resources