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()
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'm trying to generate links to Google calendar and see this tool:
https://decomaan.github.io/google-calendar-link-generator/
And the links are generated as:
https://www.google.com/calendar/render?action=TEMPLATE&text=Appointment+with+VULKOVICH%2C+BILL&details=a+Description&location=a+Location&dates=20210105T103300Z%2F20210114T103300Z
and as you can see the dates are like:
20210105T103300Z
and I am trying to convert this to my own dates but I don't know which type is this and how to format. I have the dates both, in moment or in date, but don't know how to convert.
That's ISO-8601
The first part is the date in year-month-date order, the second part is the time and the final letter indicates the timezone (here Z for 'Zulu')
Since you're using moment.js: moment().utc().format('YYYYMMDDTHHmmss[Z]'), or without a library new Date().toISOString().replace(/\W/g,'').replace(/\d{3}Z/,'Z'). This is really a duplicate of How to format a JavaScript date.
Source: comment by RobG Jan 11 at 12:58
I have a date gotten from json response. I able to filter the date to confirm that it is actual date type but I am not able to set future date to it. Below is my snippet
$rootScope.until= response.data.data.dateReceived;
//return future date
// var targetDate = new Date();
$rootScope.until.setDate($rootScope.until + 60);//adding 60 days but cannot
// So you can see the date we have created
$rootScope.until = $filter("date") ($rootScope.until), 'EEEE, MMMM d, y');
Please how can I add future dates
There seem to be two different mistakes here.
You're trying to use Date functions on a Number.
The function Date#setDate() takes as its argument the day of a
month, not the timestamp itself.
Date vs. Number
Problem
If you used new Date(response.data.data.dateReceived) to convert the number of milliseconds you received into a Date datatype, you would be able to access methods like setDate().
However, with your current code, you're trying to perform setDate() on what — to JavaScript — is just an ordinary number. It might as well be -1, since JavaScript has no idea that your number means anything more than its numeric value.
Solution
Since your input data is in milliseconds (a fact you indicated in the comments), the easiest way to accomplish this would simply be to add milliseconds to your initial timestamp like so:
const SIXTY_DAYS = 5184e6; //1000ms/sec * 3600secs/hour * 24hours/day * 60days
$rootScope.until= response.data.data.dateReceived + SIXTY_DAYS;
Just make sure that the value is a number, not a string, otherwise this will perform concatenation instead of addition.
setDate arguments
Problem
If you do have a variable with a datatype of Date (see above), you would have access to methods like Date.setDate(). However, this method's arguments are a bit different than what your code assumes.
Solution
setDate() takes in as its argument a number of days since the start of the month. If you want to add a number of days, you could do the following:
$rootScope.until= new Date(response.data.data.dateReceived);
$rootScope.until.setDate($rootScope.until.getDate() + 60);
This code will obtain the day of the month for the date, then add 60 days to that value. It will automatically handle the change in the month.
I am using Bootstrap datepicker and on selecting different values from a list its startdate is changing. It is working fine if I set the startdate 2013 from 2008 but it doesn't work if a select start date 2008 and currently its 2013.
What could be the reason here?
$('#datepicker').datepicker('setStartDate', updatedDate);
This line I am executing whenever I select different startDate.
Really need to know what updatedDate value is.
However, if you read the docs for the dtepicker the value passed in must be a string that is understandable by format
https://bootstrap-datepicker.readthedocs.io/en/latest/methods.html#setstartdate
https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#startdate
Date or String. Default: Beginning of time
The earliest date that may be selected; all earlier dates will be
disabled.
Date should be in local timezone. String must be parsable with format.
So what you pass in as the format option must match the format of your start date. If you do not set the format optin, the default is "mm/dd/yyyy"
Without seeing code, I can only hypothesize; try calling [...].datepicker('update', 'date_string'); on the object to force an update on the control.
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