1
$(".dateTime").text(Date);

gives the output:

Thu Jan 23 2014 14:25:02 GMT+0530 (India Standard Time)

what i want:

Thu Jan 23 2014

Is there any function for Date Only not time?

Faizan
  • 766
  • 2
  • 7
  • 19

4 Answers4

3

Use .toDateString()

var dateTimeEmelemt = $(".dateTime").text(Date.toDateString());

DEMO

Anton
  • 32,245
  • 5
  • 44
  • 54
0

Use toDateString() extension method;

dateTimeEmelemt.toDateString()

The above will give Thu Jan 23 2014

Chirag Vidani
  • 2,519
  • 18
  • 26
0

you can use jquery ui date picker. it will give you all the functionality you need.

here is an axample

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Format date</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
    $( "#format" ).change(function() {
      $( "#datepicker" ).datepicker( "option", "dateFormat", $( this ).val() );
    });
  });
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker" size="30"></p>

<p>Format options:<br>
  <select id="format">
    <option value="mm/dd/yy">Default - mm/dd/yy</option>
    <option value="yy-mm-dd">ISO 8601 - yy-mm-dd</option>
    <option value="d M, y">Short - d M, y</option>
    <option value="d MM, y">Medium - d MM, y</option>
    <option value="DD, d MM, yy">Full - DD, d MM, yy</option>
    <option value="&apos;day&apos; d &apos;of&apos; MM &apos;in the year&apos; yy">With text - 'day' d 'of' MM 'in the year' yy</option>
  </select>
</p>


</body>
</html>

http://jqueryui.com/datepicker/#date-formats

faisalbhagat
  • 2,142
  • 24
  • 27
  • Why use jQuery datepicker? It's an unnecessary plugin to add when the function already exists in javascript – Anton Jan 23 '14 at 09:14
  • well may be it is not required in above question as your suggested anwer tells but it gives much more possibilies of formating the dates – faisalbhagat Jan 23 '14 at 09:22
0

This is how you can do it without Date.toDateString() (just for fun :P)

var dateTimeEmelemt = $(".dateTime").text(Date);
dateTimeEmelemt = dateTimeEmelemt.split(':')[0];
var shortDateTime = dateTimeEmelemt.substr(0, dateTimeEmelemt.length - 3);
console.log(shortDateTime);

Demo

Felix
  • 37,892
  • 8
  • 43
  • 55