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.
Related
There's column which contains date in different formats (ie. YYYY-MM-DD or YYYY-DD-MM).
When I query it with format time:date, it throw an error: date/time field value out of range: "2022-23-02"
How can i solve it?
How can I check if it's YYYY-MM-DD or YYYY-DD-MM or another?
If you have no field that tells you whether it's YYYY-DD-MM or YYYY-MM-DD, you are kinda out of luck because it's possible that a value could be valid in both formats.
If you are able to redesign, and you must store the date as a string then use YYYY-MM-DD as it's easier for sorting. Optimally, just pass a JavaScript Date object to field of type date, timestamp, or timestampz to the database driver or orm and let it handle the conversion for you. Here's an example with node-postgres: https://node-postgres.com/features/types (the section labeled "date / timestamp / timestamptz")
I have some entries in a database and and they all contain a date string.
I have some TS like this
ref.LimitToFirst(10).orderByChild('date')
The problem i an having is that TS treats this as a regular string and just orders by the first number in the date. ex - 10/1/2021 would be ordered before 2/1/2021. How could i fix that ?
You can't fix this in code while depending on the database to perform the query. In Realtime Database, strings will always sort lexicographically - by their natural string order. You can't make it interpret the strings as something other than a normal string.
You will have to instead store an integer value that you can sort chronologically. In JavaScript, you can simply create a Date object and use its getTime() method field to get the Date's representation in millis since the unix epoch.
If you can't store a proper timestamp, then your only option is to read all the data and sort it yourself in your app, which will not scale well.
I'm using tabulator js library. I know there is a group option where i can group through certain fields i have in my data. I have a field date of the format MM/DD/YYYY. I want to group the data in the table by month only not the full date. How can i achieve that? I have tried splitting the string date from my date on '/' and then taking the first part of it as the month. An error on .split('/') appeared plus if it were to work, I did not know how to continue from there. Any ideas of how to achieve this?
You will need moment.js and then you can do something like:
groupBy: function(data){
return moment(data.dob, "MM/DD/YYYY").startOf("month").format("MMM-YYYY");}
Where you specify the input data format("MM/DD/YYYY"), then normalize those dates to the start of the month(startOf("month") and then return as abbreviated month name with year(format("MMM-YYYY")). You could change ```.format("MMM-YYYY") to what suits.
For demo see fiddle
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
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