?
Solved

MS ACCESS datetime text field used in WeekDayName function

Posted on 2013-11-15
8
Medium Priority
?
686 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 52

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 52

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 52

Accepted Solution

by:
Gustav Brock earned 1500 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

840 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