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
958 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

792 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