Solved

MS ACCESS datetime text field used in WeekDayName function

Posted on 2013-11-15
8
659 Views
Last Modified: 2013-12-23
Hi, I'm wondering how I might go about using a field stored as text in the WeekDayName function.

CUSTOM_FIELD is a text field of date time ex: 201311150938

I'm thinking something like this?
WeekdayName(Weekday( Format(Mid([CUSTOM_FIELD],5,2) & "/" & Mid([CUSTOM_FIELD],7,2) & "/" & Left([CUSTOM_FIELD],4),"mm/dd/yyyy"))) AS BUCKET_DAY_NAME

but this gives me a data type mismatch
0
Comment
Question by:ghettocounselor
8 Comments
 
LVL 4

Expert Comment

by:AccessGuy1763
ID: 39651859
WeekdayName() needs to be passed a number between 1 and 7 (a numerical representation of the day of the week).  Most commonly, you would call just Weekday() against a Date and wrap WeekdayName() around that.

You may or may not need to do a CDate() on the Date you are constructing before passing it to Weekday()
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39651879
that should work, check for null values in the field

place Is Not Null in the criteria row of the field [CUSTOM_FIELD]

[CUSTOM_FIELD]

Is Not Null
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39653130
To include the records with Null for [CUSTOM_FIELD] you can use:

IIf(IsDate(Format(Left([CUSTOM_FIELD], 8), "@@@@\/@@\/@@")), WeekdayName(Weekday(Format(Left([CUSTOM_FIELD] & "20000101", 8), "@@@@\/@@\/@@"), 2)), Null) As BUCKET_DAY_NAME

/gustav
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:ghettocounselor
ID: 39664271
this:
IIf(IsDate(Format(Left([CUSTOM_FIELD], 8), "@@@@\/@@\/@@")), WeekdayName(Weekday(Format(Left([CUSTOM_FIELD] & "20000101", 8), "@@@@\/@@\/@@"), 2)), Null) As BUCKET_DAY_NAME_TWO

Is working out the day but it is one day off, as in Tuesday shows as Monday, Wednesday as Tuesday.
Weekday-nov2013.png
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39665078
WeekdayName also has a localization parameter:

IIf(IsDate(Format(Left([CUSTOM_FIELD], 8), "@@@@\/@@\/@@")), WeekdayName(Weekday(Format(Left([CUSTOM_FIELD] & "20000101", 8), "@@@@\/@@\/@@"), 2), ,2), Null) As BUCKET_DAY_NAME

/gustav
0
 

Author Comment

by:ghettocounselor
ID: 39708666
This item is still giving me 1 day off, as in it is figuring that 12 / 09 (201312092304) which was a Monday is Sunday. See image from previous post.

IIf(IsDate(Format(Left([CUSTOM_FIELD], 8), "@@@@\/@@\/@@")), WeekdayName(Weekday(Format(Left([CUSTOM_FIELD] & "20000101", 8), "@@@@\/@@\/@@"), 2), ,2), Null) As BUCKET_DAY_NAME
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39708766
That's weird. The inner part:

Weekday(Format(Left("201312092304" & "20000101", 8), "@@@@\/@@\/@@"), 2)

returns 1 for Monday, thus

WeekdayName(1, ,2)

returns Monday.

/gustav
0
 

Author Closing Comment

by:ghettocounselor
ID: 39736337
In the end I think the concept and approach here are sound, something is screwy in my DB with this function. I messed and messed with it and still always found it one day off, very odd.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question