Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:51:01+00:00 2026-06-06T05:51:01+00:00

I have a calendar table in my MYSQL database with one field named datefield

  • 0

I have a calendar table in my MYSQL database with one field named datefield (type DATE).

Previously I inserted dates from 2008-01-01 to 2010-01-01 but now I want to add every day until the current date. Unfortunately, I’m completely forgotten how I did this.

I’m also wondering if there is any way to automate the process of keeping this table current.

I’m using PHP so I guess I could do a new INSERT every day? Or is there some way to do this directly in MYSQL?

thanks,
tim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:51:03+00:00Added an answer on June 6, 2026 at 5:51 am

    Here’s a quick hack:

    drop table if exists dates;
    create table dates(datefield date);
    
    
    drop procedure if exists insertDates;
    
    delimiter $$
    create procedure insertDates(start_date date)
    begin
    set @days = 0;
    set @end_date = str_to_date('1970-01-01', '%Y-%m-%d');
    
    while (@end_date < curdate()) do
    insert into dates
    select
    date_add(start_date, interval @days day)
    from (select @days:=@days+1) r
    ;
    set @end_date:=(select max(datefield) from dates);
    end while
    ;
    
    end $$
    
    delimiter ;
    
    call insertDates('2012-06-06');
    
    select * from dates;
    

    For the daily insert you can try a cron job or MySQL offers “EVENTS”, something like:

    CREATE EVENT yourDB_Schema.insertDateEachDay
    ON SCHEDULE EVERY 1 DAY
    DO
    INSERT INTO yourTable (yourDateColumn) VALUES (CURDATE());
    

    Read more about it here:

    MySQL Create Event manual entry

    An event is associated with a schema. If no schema is indicated as
    part of event_name, the default (current) schema is assumed.

    _

    Not specifying STARTS is the same as using STARTS
    CURRENT_TIMESTAMP—that is, the action specified for the event begins
    repeating immediately upon creation of the event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem... There is a table in my MySQL database that stores
I have a mysql table that contains a date field in epoch time format.
I'm building a simple availability calendar with PHP and MySQL. I have a table
I have a calendar table with data from year 2000 to 2012 (2012 wasn't
I have a calendar created with a table. Users can mark the dates on
I have a table of Calendar event information (Date, username). I want to print
I have a table with 2 rows, one of which represents date and the
Possible Duplicate: PHP/MySQL - Format date/time I have input field (name:day1 and varchar) to
I have a mysql table with users and their weekly calendar. Every user can
At the moment I have 2 different mysql queries: Query 1 SELECT monthname( calendar.datefield

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.