How do I convert the string 03-MAR-2021 to the string 20210303 with Javascript in Pentaho Spoon
start_date="03-MAR-21";
var new_startDate= new Date(start_date);
var date= moment(new_startDate).format('yyyyMMdd');
See common date formats
start_date="03-MAR-2021";
var date= str2date(start_date, "dd-MMM-yyyy");
var formatedDateString = date2str(date, "yyyyMMdd");
I get the date in a string like '03-Mar-2021' but I need to convert to string '20210303' (YYYYMMDD) I can make in JScript or directly on Query. But I have problems when I try to
Related
how do I convert something like
2020-12-01T15%3A48%3A39.862Z
to a timestamp format of
2018-09-15T15%3A53%3A00-07%3A00?
I am not very familiar with timestamp formats and manipulation of datetime in Javascript...
You can turn it into a DateTime directly, you just have to decode all that %3A stuff first:
var timeString = '2020-12-01T15%3A48%3A39.862Z';
var decodedTimestring = decodeURIComponent(timeString);
var date = new Date(decodedTimestring);
console.log(date.toLocaleString());
I have getting a dateformat like '23.10.2017'. I need to format this in to
'10/23/2017'
I just tried
var crDate='23.10.2017';
var newDateF=new Date(crdate).toUTCString();
but it showing InvalidDate
can anyone help to change the format.
Thanks in advance
I don't think using Date() is the solution. You can do
var crDate = '23.10.2017';
var newDateF = crDate.split(".");
var temp = newDateF[0];
newDateF[0] = newDateF[1];
newDateF[1] = temp;
newDateF.join("/");
This splits the string into an array, swaps the first and second elements, and then joins back on a slash.
A regex replacement will do the trick without any Date functions.
var date = '23.10.2017';
var regex = /([0-9]{2})\.([0-9]{2})\.([0-9]{4})/;
console.log(date.replace(regex,'$2/$1/$3'));
Just use moment.js if you can :
// convert a date from/to specific format
moment("23.10.2017", "DD.MM.YYYY").format('MM/DD/YYYY')
// get the current date in a specific format
moment().format('MM/DD/YYYY')
Moment is a very usefull and powerfull date/time library for Javascript.
Hi I have use the string object for represent the date in the following format
var date="18/01/2011";
var dateFormat="dd/MM/yyyy";
Note:
In my scenorio i have use the dd/MM/yyyy format;
dateFormat will be different in my client side.
how to convert these date default JavaScript dateFormat as MM/dd/yyyy in Generic way.
I have tried in by split date by and swap the month ,date to achieve this requirement. But in my client side i dont know about the format of the date how to convert any other format to default Javascript format
Hope this helps:
var date="18/01/2011";
var parts = date.split('/');
var result = new Date(parts[2], parts[1], parts[0]);
var datestring = "2014-02-27:04:05";var d = Date(datestring);
I am debugging a small application with some functionality which would only run in Chrome. The problem lies in a datepicker where you choose a date and time and the datepicker concaternates it into a datetime-string.
Anyway the string looks like this: 2012-10-20 00:00.
However, the javascript that uses it now just takes the string and initialize an object with it like this: new Date('2012-10-20 00:00');
This is resulting in an invalid date in Firefox, IE and probably all browsers but Chrome.
I need advise in how I best could transform this datestring to a Date object in javascript. I have jQuery enabled.
Thanks for your sage advise and better wisdom.
If the string format is always as you state, then split the string and use the bits, e.g.:
var s = '2012-10-20 00:00';
var bits = s.split(/\D/);
var date = new Date(bits[0], --bits[1], bits[2], bits[3], bits[4]);
It's just the simplify version:
var newDate = new Date('2015-04-07 01:00:00'.split(' ')[0]);
if str = '2012-10-20 00:00'
new Date(str.split(' ')[0].split('-').join(',') + ',' + str.split(' ')[1].
split('-').join(','))
should do the trick
use parseExact method
var date = new Date.parseExact(dateString, "yyyy-mm-dd hh-mm");
My value contains "08.07.1987", how to retrieve the date object for this string. new Date(val) gives correct date object values only for the string value that contains "/" format. can any one let me know hot to create date object for the values which contains "." or "-". in its format.
How about just adjusting the string to suit your needs?
var date1 = new Date("08.07.1987".replace('.','/'));
var date2 = new Date("08-07-1987".replace('-','/'));
You will need to be careful when asking Javascript to interpret a date in this format. As you can probably imagine, a date listed as "08.07.1987" doesn't really specify whether it's August 7th or July 8th.
In general, your best bet will be to specify a date format and parse accordingly.
you have to split the string into tokens for month date and year and then create it using JS Date API.
var date="08.07.1987";
var newDate = date.replace(/(\.|-)/g,"/"));
var dateObject = new Date(newDate);
Replace the delimiters?
var dateStr = "08.07.1987",
dateObj = new Date(dateStr.replace(/[-.]/g,"/"));
Of course you can encapsulate that in a function if need be...
try this new Date("08.07.1987".replace('.','/','g')); tested on firefox only