473,785 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking if date entered is a weekend

2 New Member
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 9793
mrhoo
428 Contributor
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
welshboi
2 New Member
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 Recognized Expert Moderator MVP
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
JaXXXoN
1 New Member
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
7967
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 2005", (or a timestamp that could be formatted). I have been thinking about creating a loop that increases the source date $myDate with 24*60*60 until date("l", $myDate) = "Monday" but maybe I am trying too complicated solutions and overseeing...
2
3476
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
13462
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 weekend date for any given date. Any information is appreciated. Thanks, Aditya.
2
1702
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 the 'Q' (Quarter), and NEXT_DAY translations. Thanks. SELECT TO_CHAR(SYSDATE, 'Q') Q, TO_CHAR(SYSDATE, 'MM') MON, TO_CHAR(NEXT_DAY(SYSDATE,'SUNDAY' ),'MM/DD/YYYY') WEEKEND,
5
14896
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 geographical region. I have written a query which prompts the user for the start and end dates. It also filters for entries which pertain to the particular geographical region. I'm not sure where to go from here.
1
6135
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 start date & an end date & may span a weekend) If a start date (workday) & an end date (workday) are on the same day then the number of workdays will equal zero Some eg's.
28
2040
by: romy | last post by:
What's the easiest way to verify the user had entered a valid date ?
6
14373
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, excluding holidays and weekends.' I didn't want to build a table of holidays that would have to be continuously updated, so I searched high and low for a function that would tell me whether a given date was a holiday, to no avail. I did find an...
4
1788
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 december I'm also trying to do it the hard way, without the use of any modules .. i feel this will help my perl skills.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.