473,405 Members | 2,176 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,405 software developers and data experts.

Weekday from Date problem

Can someone tell me why this query works:
Expand|Select|Wrap|Line Numbers
  1. SELECT WeekdayName(Weekday(#17/02/2007#)-1) AS [Day]
and this one doesnt
Expand|Select|Wrap|Line Numbers
  1. SELECT WeekdayName(Weekday(#18/02/2007#)-1) AS [Day]
what I am trying to achieve is to get weekday from date obviously. a
Appreciate any help
Nov 3 '07 #1
4 3829
Jim Doherty
897 Expert 512MB
Can someone tell me why this query works:
Expand|Select|Wrap|Line Numbers
  1. SELECT WeekdayName(Weekday(#17/02/2007#)-1) AS [Day]
and this one doesnt
Expand|Select|Wrap|Line Numbers
  1. SELECT WeekdayName(Weekday(#18/02/2007#)-1) AS [Day]
what I am trying to achieve is to get weekday from date obviously. a
Appreciate any help
you are missing out the second argument of the WEEKDAY function try this and closely compare yours against these. The second argument determines the starting point for the week ie: 1 equals Sunday 2 equals Monday and so on

Your fault is that you at some point are telling it use a value of 0-1 which is of course a negative falling outside of the range 0 to 7

WeekdayName(Weekday([Date],0))
or this
WeekdayName(Weekday([Date]-1,0))

where [Date] equals the name of your field being tested when used in a query


Jim :)
Nov 3 '07 #2
missinglinq
3,532 Expert 2GB
what I am trying to achieve is to get weekday from date
First off, your code is going to retrieve the week day name of the day before your date, not the week day name of the actual date. Is this what you want?

FirstDayOfWeek is optional and defaults to 1, which means Sunday; that's not the issue here.

The reason this identical syntax fails (I think) is this:

WeekdayName(Weekday(#17/02/2007#)-1 )

is retrieving the WeekDayName of 17/02/2007 (Saturday) and then, with the -1, is yielding the previous WeekDayName, which is Friday. And this works fine!

The problem when you change the date to 18/02/2007 is that 18/02/2007 is a Sunday. Then, with the -1, you're once again trying to get the WeekDayName that comes before Sunday, and in Access' mind, when the FirstDayOfWeek is set to Sunday, there is no day of the week before Sunday! And so the code fails if the day entered is a Sunday.

The way around this is to subtract your 1 from the date first, then evaluate the WeekDayName from this date. You do this by including a second set of parentheses .

Instead of

WeekdayName(Weekday(#18/02/2007#)-1)

use

WeekdayName(Weekday( (#18/02/2007#)-1) )

Linq ;0)>
Nov 3 '07 #3
Thanks guys!! You're awesome - both resolutions sound fine. As you said - my fault of trying to change begining of the week by (-1). Thanks again!
Nov 3 '07 #4
missinglinq
3,532 Expert 2GB
So, you really were only trying to get the WeekDayName for the given date? Then plain old

WeekdayName(Weekday(#18/02/2007#))

will work unless you need the firstdayof week to be something other than Sunday.

Glad we could help!

Linq ;0)>
Nov 3 '07 #5

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

Similar topics

6
by: dr. zoidberg | last post by:
Hello, I have this: Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to do is to associate days with its current week dates, for example: Mon (05.01.2004); Tue...
2
by: David Morgan | last post by:
Hi Hopefully the subject says it all. Given a weekday, (1 to 7) and an occurrence with in a month, (1 to 4), I need to ascertain the date on which it first occurs in any given month and year. ...
2
by: Chumley the Walrus | last post by:
I can't locate a weekday function in asp.net, whereas I just want to grab the weekday associated with a given date. I'm using this date format {0:MM/dd/yyyy} in references in my code, just need to...
1
by: Kd | last post by:
I am currently using a form with Weekdays Mon Tues Wed Thur Fri This is generated by a table that the days are being entered manually I would like to create a form that the days updated...
14
by: Divit | last post by:
I want my code to tell me that (today) April 12th is the second wednesday of the month. And only thing I can find is the function to tell me what date belongs to the 2nd day in a given month and...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
4
by: dgmoore | last post by:
I've hit a snag - I know this is easy, but the logic is escaping me. I need to set criteria in a query to find dates in a date field that lie between Tuesday of the current week and Tuesday of the...
0
by: Rudi Hausmann | last post by:
Hi! I have a column with a date. In another column I want to show the weekday of this date. I have following code: <asp:BoundField DataField="myDate" HeaderText="WeekDay"...
6
Cintury
by: Cintury | last post by:
Using Access 2003 (Access 2000 file format) on Windows XP I have a query that pulls from 2 tables that includes a date as well as other data. What I need is code to put in the SQL view, if this is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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...

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.