PHP function to match date - javascript

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

Related

How can I check month and day order in mixed date format?

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")

is there a way i can group data by "Month" on tabulator js while having a full date?

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

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.

Casting from Timestamp/String to Date

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

Categories

Resources