?
Solved

convert 2014-02-04 00:00:00 to dd/mm/yyyy in jquery

Posted on 2014-07-29
6
Medium Priority
?
1,577 Views
Last Modified: 2014-08-01
Hi All,
    I'm currently retrieve the date field from Sharepoint and display on a page using jquery, the date retrieved using SPServices as below:

2014-02-04 00:00:00

how to convert the date to dd/mm/yyyy format?

My code:
$().SPServices({
                      operation: "GetListItems",
                      async: false,
                      listName: "LibraryName",
                      CAMLViewFields: "<ViewFields><FieldRef Name='DateToDisplay'/></ViewFields>",
                      CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + ID + "</Value></Eq></Where></Query>",
                      completefunc: function (xData, Status) {
                        $(xData.responseXML).SPFilterNode("z:row").each(function() {
                          DateToDisplay= ($(this).attr("ows_DateToDisplay"));
                        });
                }
                  });
0
Comment
Question by:seebeelim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 40227016
This extra date formatting plugin comes highly recommended;

https://github.com/phstc/jquery-dateFormat

The documentation shows how to apply a mask to the conversion.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227211
date="2014-02-04 00:00:00"
date=date.replace(/-/g,"/").split(" ")

date=new Date(date[0])
alert(addzero(date.getDate()) + '/' + addzero(date.getMonth() + 1) + '/' +  date.getFullYear());

function addzero(el) {
    return ("0" + el).slice(-2)
}

Open in new window

0
 
LVL 8

Expert Comment

by:Jayaraja Jayaraman
ID: 40227324
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 15

Accepted Solution

by:
Insoftservice earned 645 total points
ID: 40232505
You can use date.js to achieve this:

var date = new Date('2014-01-06');
var newDate = date.toString('dd-MM-yy');

Alternatively, you can do it natively like this:

var dateAr = '2014-01-06'.split('-');
var newDate = dateAr[0] + '-' + dateAr[1] + '-' + dateAr[2];
0
 

Author Comment

by:seebeelim
ID: 40233957
Hi insoftservice,
   What if i want to convert "2014-02-04 00:00:00" together with the time not just date?
0
 

Author Comment

by:seebeelim
ID: 40233985
Hi insoftservice. Thanks for the code. I just updated with extra yy and it works.

var date = new Date('2014-01-06');
var newDate = date.toString('dd-MM-yyyy');
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question