Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find day of date using JQuery

Tags:

jquery

How can I get day of given date using jQuery? In c# I do it like this

 if(MyDate.DayOfWeek == DayOfWeek.Sunday)

How can i do this in jQuery?

like image 226
Pankaj Avatar asked May 19 '10 07:05

Pankaj


People also ask

How can get today day in jquery?

You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d.

How to get the day from date js?

Javascript date getDay() method returns the day of the week for the specified date according to local time. The value returned by getDay() is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.

How can I get current date in jquery in dd mm yyyy format?

get current date in jquery in dd/mm/yyyy format” Code Answer. var mm = String(today. getMonth() + 1).

How to get the weekday in js?

Call the getDay() method on the Date object to get the day of the week. The getDay method returns the day of the week for the specific date, represented as an integer between 0 and 6 , where 0 is Sunday and 6 is Saturday.


2 Answers

You could use JavaScript's Date.getDay()

  $(document).ready(function() {

    var d = new Date();

    alert(d.getDay());
  } );

As stated you don't need jQuery to use this but I've wrapped it in jQuery for your pleasure. As stated by nc3b the result its 0 based where 0 is Sunday.

like image 108
Johnno Nolan Avatar answered Sep 20 '22 01:09

Johnno Nolan


Using javascript, you can find the day of week: Date.getDay(); Say you have something like this:

Date d = new Date(...);
d.getDay(); // returns day of week.

Careful as it's zero-based so it will return from 0 to 6.

like image 21
nc3b Avatar answered Sep 20 '22 01:09

nc3b