[Solved] Query dates by month

Creating tables and queries
Post Reply
younghammer
Posts: 3
Joined: Mon Jun 25, 2012 11:44 pm

[Solved] Query dates by month

Post by younghammer »

I'm fairly new to Base and ran into a wall.

I have a database "Customers" containing over 600 entries, with first names, last names, addresses (#, street, zip), birth dates and sites visited. I want to make a query that will list my customers by month of birth, so I can send them a birthday card. My DOB field is of DATE type and looks like MM/DD/YY.

I tried using the query wizard and I cannot figure out the criteria I should using. Nothing works and I'm stalled.

Please, help, and try to keep it simple for me. I know nothing of mySQL and Basic.

Thank you.
Last edited by younghammer on Tue Jun 26, 2012 8:01 pm, edited 1 time in total.
OpenOffice 3.3.0 Windows 7
User avatar
DACM
Volunteer
Posts: 1138
Joined: Tue Nov 03, 2009 7:24 am

Re: Query dates by month

Post by DACM »

younghammer wrote:...I know nothing of mySQL and Basic.
Are you using a MySQL database? Or does Base say "Embedded database" in the status bar at the bottom of your main Base window? Or perhaps something else?

Perhaps see:
https://www.google.com/search?sugexp=ch ... uery+month

Basic (language), on the other hand, is not necessary to solve this issue.
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
younghammer
Posts: 3
Joined: Mon Jun 25, 2012 11:44 pm

Re: Query dates by month

Post by younghammer »

It says Embedded Database.
OpenOffice 3.3.0 Windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Query dates by month

Post by Villeroy »

Select all columns (*) plus a calculated month column:

Code: Select all

SELECT *, MONTH("Birth Date") AS "Month" 
FROM "Your Table" 
ORDER BY "Month"
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Sliderule
Volunteer
Posts: 1279
Joined: Thu Nov 29, 2007 9:46 am

Re: Query dates by month

Post by Sliderule »

Just to add on to the sound advise given by Villeroy above, assuming you want to only see the records from your table ( "Customers" ), and, you want want to be prompted to input a given month number ( 1 to 12 ) to bring back all the records where "DOB" is that month, follow these steps:
  1. Open your OpenOffice Base file ( *.odb )
  2. On the left, click on the Queries icon
  3. Under Tasks, click on: Create Query in SQL View...
  4. Copy and paste the following SQL

    Code: Select all

    SELECT 
       TO_CHAR( "DOB", 'MM/DD' ) AS "Birthday Date", 
       "Customers".* 
    
    FROM "Customers" AS "Customers" 
    
    WHERE MONTH( "DOB" ) = :Enter_Month_Number_1_to_12 
    
    ORDER BY "Birthday Date" ASC, 
             "Customers"."DOB" ASC
  5. Run your Query, EITHER:
    1. F5 key
    2. Run Query icon on Toolbar
    3. From the Menu: Edit -> Run Query
  6. When you are prompted, enter the month number . . . a number . . . from 1 to 12
  7. Save the Query so you can run it again / later
Explanation: The above Query will display month and day ( 'MM/DD' ) of the "DOB" field as "Birthday Date". And, you are prompted, so, only records for a given input month ( 1 to 12 ) will be returned. Additionally, the records returned will be in the ORDER ( sorted ) by DAY within the given month. :bravo:

I hope this helps, please be sure to let me / us know.

Sliderule

Thanks to add [Solved] in your 1st post Subject (edit button top right) if this issue has been resolved.
younghammer
Posts: 3
Joined: Mon Jun 25, 2012 11:44 pm

Re: [Solved] Query dates by month

Post by younghammer »

Sliderule:

It works perfectly! I appreciate how you kept your explanations simple and easy to follow. Now I can go forward with my birthday card idea.

Thank you! :P
OpenOffice 3.3.0 Windows 7
gr8fulbishop
Posts: 1
Joined: Sat Nov 24, 2012 11:32 pm

Re: [Solved] Query dates by month

Post by gr8fulbishop »

I have seen a lot of really good information and solutions, but some of it is not working for me. I’m not sure what I am doing wrong. I have a list of data on properties in my area. I am able to create a pivot table with the data that I need. However, I am trying to group the data by month. The original dataset has the date formatted as “date” - mm/dd/yyyy.

However, when I click on the first date in the pivot table and click “Data” -> “Group and Outline” -> “Group", it creates a copy of the date field instead of displaying a popup.

Is there something that I have done wrong? Data file is attached. Thanks for you assistance.
Attachments
Clinton.ods
Data File
(29.35 KiB) Downloaded 442 times
MAC 10.8.2 / OpenOffice 3.4.1
User avatar
Sliderule
Volunteer
Posts: 1279
Joined: Thu Nov 29, 2007 9:46 am

Re: [Solved] Query dates by month

Post by Sliderule »

gr8fulbishop:

Just as an FYI ( For Your Information ) . . . your question here is really a Calc ( Data Pilot ) question, rather than a Base question, so, I would suggest if you have additional questions about Data Pilot, ask in the Calc forum. :super:

To answer your question, I have attached below, a copy of your Calc file, using Data Pilot, and, having it GROUP by month. Below, I described what I did.
  1. I opened your Calc file.
  2. In Sheet1, I changed ( altered ) the Close Date column, that is, I 'converted' the TEXT values to Date values ( I removed the beginning single quote ( ' ) so the result was a real date ( stored in the spreadsheet as an integer ).
  3. In your Data Pilot, in sheet: Pivot Table_Sheet1_1 , click on one of the dates, for example, 08/27/12
  4. Press F12, OR, From the Menu: Data -> Group and Outline -> Group...
  5. In the Grouping popup, in the Group By section, click the radio button for Intervals, and, choose, Months
  6. Click on the OK button
  7. Smile and say: "Gee Sliderule, that was easy. Now all I have to do is let the forum know I am able to Group my Calc output by Month, using DataPilot." :bravo:
I hope this helps, please be sure to let me / us know.

Sliderule
Nick N,
Posts: 140
Joined: Wed Aug 09, 2023 2:10 pm

Re: [Solved] Query dates by month

Post by Nick N, »

@qwerty

Had to copy/paste yr spreadsheet and give correct format to each field.

I joined for you subsequent test file with your data listed in the report to suit your needs. Pls look at it.

Regards
Attachments
Test Rev 1.odb
(14.8 KiB) Downloaded 227 times
Libre Office 6.0.7 on Ubuntu 18.04
User avatar
robleyd
Moderator
Posts: 5087
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [Solved] Query dates by month

Post by robleyd »

Did you intend to post this in viewtopic.php?t=110671 ?
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Post Reply