How to convert date format from dd-MMM-yyyy to yyyymmdd in Javascript?

kumareloaded

I've an input text box with a date-picker, when the user selects a particular date, the date say 09-Dec-2014 gets applied to the input text box. On submit, I want the date to be passed to the server in yyyymmdd format say 20141209. So how to convert the date format in javascript?

var date = new Date(Date.parse('09-Dec-2014'));

Above code gives me 'Invalid date'.

Searched the net for solution but was not able to find for my problem.

Can someone help me out?

Thanks.

kumareloaded

Thanks for the answers Danyal Sandeelo and Jeeva Jsb.

I was able to get the date in yyyymmdd format using the code given below.

var date = '09-Dec-2014'.split("-");
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
for(var j=0;j<months.length;j++){
    if(date[1]==months[j]){
         date[1]=months.indexOf(months[j])+1;
     }                      
} 
if(date[1]<10){
    date[1]='0'+date[1];
}                        
var formattedDate = date[2]+date[1]+date[0];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Convert integer (YYYYMMDD) to date format (mm/dd/yyyy) in python

Reformatting a Date from DD-MMM-YYYY to YYYYDDMM or YYYYMMDD

Change date format from "yyyymmdd" to "mm/dd/yyyy"

Change date from YYYYMMDD to YYYY-MM-DD Javascript

How to change Date format (dd-mmm-yyyy) in bootstrap datepicker

How to convert a date format YYYY-MM-DD into integer YYYYMMDD in Presto/Hive?

How to convert date format from dd/mm/yyyy to yyyy-mm-dd using carbon on Laravel

R How to change format of date from MM/DD/YYYY to YYYYMMDD and YY-Month (Abbreviated Month)?

Convert string of YYYYMMDD to YYYY-MM-DD Date format in Snowflake

Convert the mysql date format to dd-mmm-yyyy in mysql

How to convert date format from YYYY-DD-MM to DD-MM-YYYY

sort array of date of format 'dd/mmm/yyyy'

How to convert date format from dd/MM/YYYY to YYYY-MM-dd in swift

How to convert ISOString to date format dd/mm/yyyy using javascript

How to get Date in the below Format "dd MMM, yyyy z"

convert a date in pig from YYYY-mm-dd to YYYYmmDD

convert date format from "mm/dd/yyyy hh:mm:ss a" to "dd MMM yyyy" in swift

How to convert a string to a date from dd mmm yyyy format in SQL Server

Convert Date String from YYYYMMDD to DD Mon YYYY

Date Argument format conversion from YYYYMMDD to DD-MON-YYYY

How to order items from Room database by date with "MMM dd yyyy" format

Convert yyyymmdd chararray to yyyy/mm/dd date format

Regex for date format dd Mmm yyyy from email header

How to format date in javascript as DD-MMM-YYYY?

How to extract date from a string of format dd-mmm-yyyy in js

How can I convert to date format (DD MMM YYYY) in file without writing to new file the output

Check date format is DD-MMM-YYYY

Format date to DD-MMM-YYYY in Javascript

Reformatting Text from "yyyymmdd" or "yyyyddmm" format to "dd MMM yyyy" format in SQL Server