Solved

In Access, I need a Query to Convert a Date to the First Day of that Date's Month and Year

Posted on 2011-09-12
5
900 Views
Last Modified: 2012-05-12
I am trying to extract the month and year from a mm/dd/yyyy date. I need to Join it later with a Table that has Months and Years (Formatted mmm-yy) ...but the actual date values for those are always the first of the month, e.g., Apr-04 is really 4/1/2004

If I don't have the date values match, the Join finds no records equal and returns nothing.

So...I need to turn a date like 4/25/2004 into 4/1/2004
0
Comment
Question by:Rex85
  • 2
  • 2
5 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36524361
use this to get the first day

firstDay:dateserial(year([dateField]),month([dateField]),1)
0
 

Author Comment

by:Rex85
ID: 36524566
I think I am doing something wrong. I pasted your expression into the Select statement...

SELECT GetWeekEndingDate([Created on]) AS WeekEndingDate, Sum(KO_QN_Data.[DefectQty (ext)]) AS Total_QNs, firstDay:dateserial(year([Created on]),month([Created on]),1) AS First_Day INTO QPR_Interstuhl_QNs_tbl
FROM KO_QN_Data

...and got the following error.

I couldn't save the query.
0-syntax-error.jpg
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 36524639


SELECT GetWeekEndingDate([Created on]) AS WeekEndingDate, Sum(KO_QN_Data.[DefectQty (ext)]) AS Total_QNs,  dateserial(year([Created on]),month([Created on]),1) AS First_Day INTO QPR_Interstuhl_QNs_tbl
FROM KO_QN_Data
0
 

Author Closing Comment

by:Rex85
ID: 36524685
Fantastic! Thank you very much.

Rex
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 36524742
This expression will yield the first day of the current month:

CDate(Month(Date) & "/1/" & Year(Date))

Substitute a Date field or variable for the Date function to get the first day of a specified month
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of utilizing SQL Server views 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 Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

863 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

23 Experts available now in Live!

Get 1:1 Help Now