Solved

MS ACCESS datetime text field used in WeekDayName function

Posted on 2013-11-15
8
666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 50

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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 50

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 50

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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