Format a date by reversing the position of the year, month and days - date

The value received from the Date Picker is in the format "02-06-2020" (formatted with mask = "DD-MM-YYYY" in q-date).
I need to convert it to "2020-06-02" format to send it to the server.
I tried the following, but I get undefined.
Example:
let myDate = "02-06-2020";
console.log(date.formatDate(myDate, "YYYY-MM-DD")) //undefined
I would appreciate suggestions for finding a solution.
Thanks.

You can use moment js.
moment(moment('13-01-2020', 'DD-MM-YYYY')).format('YYYY-MM-DD');
or
date.split("-").reverse().join("-");

Related

How to convert local date to UTC?

Can anyone help me with the following:
I have am recording date in my UI, which is IST +5:30
First, I want to convert that date to UTC with start time 00:00
Second, I want to convert that to long time (which I think it is
Unix)
Saved to DB
Third, I want to convert a long time back to UTC in format
MM/DD/YYYY.
This is what I tried so far:
const dateUnix => moment(myMomentObj)
.utc()
.format(DATE_TIME_FORMATS.TIME_STAMP);
The above gets a long time which I don't know if it correct.
const dateMoment = moment.unix(dateUnix)
const formatedDate = dateUnix.format('L'); //which should be in MM/DD/YYYY format
But the formatDate is giving me something like 02/12/15235 which is wrong.
Any help is appreciated.
Thanks in advance.
This code might help you
//input in IST +5:30
var inputDate = moment().utcOffset("+05:30").format();
console.log(inputDate);
//moment.unix outputs a Unix timestamp
var unixTs = moment.utc(inputDate).unix();
console.log(unixTs);
//there is a unix method that accepts unix timestamps in seconds followed by format to format it
var formattedDate = moment.unix(unixTs).format("MM/DD/YYYY");
console.log(formattedDate);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

Get the whole range of date in SAS

I know the date in SAS looks like 01Jan2017. What I want is 1 January 2017. Is there function to make it?
Thank,
Andrea
Your question is pretty vague - it's hard to tell if you just want to display it differently or store it differently.
Display it differently: Just change the format to keep the date as a number in the background (number of days since 01JAN1960) but display it how you would like.
data ds1;
date = '01JAN2017'd;
format date WORDDATX20.;
run;
Store it differently: You can use the put function to create a separate character variable containing the formatted version of your date.
data ds2;
date1 = '01JAN2017'd;
date2 = put(date1, WORDDATX20.);
run;
Answers provided by Bhavika and pm2r should also help you understand what's going on here.
your code would look like this:
data _null_;
length date1 8. string $40;
date1=today();
string = cats( date1 );
put string=;
string = cats( put(date1,date10.) );
put string=;
string = cats( put(date1,WORDDATX20.) );
put string=;
run;
and the output would be:
string=20838
string=19JAN2017
string=19 January 2017

how to convert time to eppoch time based on date?

I need a javascript function which should take two arguments they are date and time (i.e 9 ,10 ,18,19 etc) and it should return eppoch time for that exact date and time?
please help me?
Try something like this..
var myDate = new Date("July 1, 1978 02:30:00");
var myEpoch = myDate.getTime()/1000.0;
document.write(myEpoch);

Groovy date format for UTC with milliseconds

I'm having trouble finding a good way of formatting a UTC-time stamp with this format: yyyyMMdd-HH:mm:ss.<three additional digits>
I wasn't able to find any character that represents milliseconds/hundredths, I'm not even sure this is possible, to parse that format that is.
Ideally I'd like to use the parseToStringDate that's part of the Date library.
My plan b is to convert yyyyMMdd-HH:mm:ss to milliseconds and then add the three last digits to that number.
Use yyyyMMdd-HH:mm:ss.SSS
This will get you milliseconds as well.
Test Code:
def now = new Date()
println now.format("yyyyMMdd-HH:mm:ss.SSS", TimeZone.getTimeZone('UTC'))
I would convert it like that:
def now = new Date()
println now.format("YYYYMMdd-HH:mm:ss")
You can try this:
TimeZone.getTimeZone('UTC')
Date date = new Date()
String newdate = date.format("YYYY-MM-dd HH:mm:ss.Ms")
log.info newdate

Converting Date in Extjs

I have a Date string of following format:
'31-OCT-2013'
How do I convert this into Date of following format using Extjs 4:
'08/31/2013'
I am using IE8.
If you have string "31-OCT-2013", you need to:
Convert it into date object
var myDate = Ext.Date.parse("31-OCT-2013", 'd-M-Y');
Format it to as you want
Ext.Date.format(myDate, 'm/d/Y');
Try something like this:
If your day representation would be 2 digit with leading zero, then apply this
var date = Ext.Date.parse("31-OCT-2013", 'd-M-Y');
console.log(Ext.Date.format(date, 'm/d/Y'));
But if your day representation would be without a leading zero, then apply this
var date = Ext.Date.parse("31-OCT-2013", 'j-M-Y');
console.log(Ext.Date.format(date, 'm/d/Y'));
Check the docs for Ext.Date