Solved

MS ACCESS datetime text field used in WeekDayName function

Posted on 2013-11-15
8
648 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
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ghettocounselor
Comment Utility
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now