[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
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
Medium Priority
?
1,220 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
[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
  • 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

656 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