473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Checking if date entered is a weekend

Hi all, long time reader, first time poster :D

I've got a page i've put together in javascript, and one of the fields takes the date (in dd/mm/yyyy) format.

What I'm trying to do, is if a user enters a date which falls on a weekend (eg, 07/11/2009), then to throw an error.

I've had a play, but i'm very confused and couldn't get anything to work :(

Fingers crossed someone can help :D

Thanks
Nov 3 '09 #1
4 9762
mrhoo
428 256MB
Create a new Date object from the input and
use its getDay() or getUTCDay() method.

Saturday returns 6, Sunday is 0.

If d is a date object, d.getDay()%6==0 is true if the day is Saturday or Sunday.
Nov 3 '09 #2
I'm using the following script from the site below to check if the date entered is valid first of all, can I be cheeky/a pain and ask where in the script would I add your check?

Thanks

http://javascript.internet.com/forms/validate-date.html
Nov 3 '09 #3
acoder
16,027 Expert Mod 8TB
Anywhere within the validation part of the function, though the function itself isn't the best out there. The function doesn't convert to the Date object. Try doing that. For the Date object, see https://developer.mozilla.org/en/Cor...e/Objects/Date.
Nov 8 '09 #4
I'm fairly certain I remember seeing weekend and leapyear detection as a feature when I was checking out this library:

http://fisforformat.sourceforge.net/

It has a ton of great date related stuff and is the best tool I've found for formatting Date Objects.
Nov 28 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Martien van Wanrooij | last post by:
I would like to retrieve, let us say, the First Monday after a certain date, so my (imaginary) function could be something like echo weekdayAfter("28 July 2005", "Monday") should return "1 August...
2
by: AdityaK | last post by:
Is there anyway I can get weekend date for a given date using DB2 query? I couldn't find any DB2 function that can be used to do so. Thanks, Aditya
7
by: AdityaK | last post by:
Is there a way to find Weekend date for a given date using a DB2 query? I see that there are scalar functions such as DAY, DAYOFMONTH, DAYOFWEEK,etc are available...but couldn't find one to get a...
2
by: gimme_this_gimme_that | last post by:
Might some kind soul take on this Oracle statement and translate it into DB2? Yes ... I know the equivalent of SYSDATE is CURRENT TIMESTAMP, and that DUAL is SYSIBM.SYSDUMMY1. But I'm puzzled by...
5
by: BlackFireNova | last post by:
I need to write a report in which one part shows a count of how many total records fall within the working days (Monday - Friday) inside of a (prompted) given date range, in a particular...
1
by: Wayne | last post by:
Hi all I'm trying to calculate the number of days (or workdays) between 2 given dates that do not include weekend days or public holidays (public holidays are user defined from a dbase, have a...
28
by: romy | last post by:
What's the easiest way to verify the user had entered a valid date ?
6
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future,...
4
by: g0uki | last post by:
Hi all, Hope someone can help, i get the date in the format of 12/12/2008 i 'd like to find out what day this is on, either a weekday/weekend. so output would be: 12/12/2008 midweek: fri 12...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.