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 1065115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:45:39+00:00 2026-05-16T19:45:39+00:00

Im working on a database that store dates in a varchar(10) mysql field (so

  • 0

Im working on a database that store dates in a varchar(10) mysql field (so sad).

I can not alter the database structure (im building a small plug-in), but i have to query the database finding rows where this data field is between the next 10 days.

Example:

| fid | fdate      |
|  1  | 10/09/2010 |
|  2  | 17/09/2010 |
|  3  | 19/09/2010 |

I have to get the rows with fid 1 and 2, becose the date is <= now + 10 days.

Usually i make this kind of query:

SELECT fid FROM table WHERE fdate <= DATE_ADD(NOW(), INTERVAL 10 DAY);

Or, if the date is in the format `yyyymmdd’:

SELECT fid FROM table WHERE fdate <= DATE_FORMAT(NOW(), '%Y%m%d');

But theyre useless with the format dd/mm/yyyy.

I’ve figured out with

SELECT fid, CONCAT(SUBSTRING(fdate, 7, 4), SUBSTRING(fdate, 4, 2), SUBSTRING(fdate, 1, 2)) AS mydate FROM table HAVING mydate <= DATE_ADD(NOW(), INTERVAL 10 DAY);

but i guess it is a bit an overkill rebuilding the date format with concat and substring, and the having clause wont help the query speed.

Any idea?

EDIT

After Adriano’s comment, the right solution is

SELECT fid FROM test WHERE STR_TO_DATE(fdate, '%d/%m/%Y') <= DATE_ADD(NOW(), INTERVAL 10 DAY);

so i can avoid the concat and having clause.

  • 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-05-16T19:45:40+00:00Added an answer on May 16, 2026 at 7:45 pm

    What about using str_to_date() to create a date from your format?

    EDIT after reading your comment, I created a table like yours:

    mysql> SELECT fid, fdate FROM test;
    +------+------------+
    | fid  | fdate      |
    +------+------------+
    |    1 | 10/9/2010  | 
    |    2 | 17/9/2010  | 
    |    3 | 19/09/2010 | 
    +------+------------+
    

    and then did

    mysql> SELECT fid FROM test WHERE STR_TO_DATE(fdate, '%d/%m/%Y') <= DATE_ADD(NOW(), INTERVAL 10 DAY);
    +------+
    | fid  |
    +------+
    |    1 | 
    |    2 | 
    +------+
    

    Seems to work. What exactly do you get?

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

Sidebar

Related Questions

I am working on a project that must store very large datasets and associated
I'm working on a site where a user could select certain dates that apply
I have a MS SQL database that I am working on, within this database
I am planning a PHP application that needs to store date/times in an MSSQL
I'm working on a .Net WinForms appliation that is connecting to a legacy RDB
I'm working on a project now that will require me to enable users to
I'm working on a Java project for class that stores workout information in a
Ok, i'm a bit confused. I am working on a project that have to
I need to begin working with milliseconds in .Net 3.0. The data will be
I have a very simple ASP.Net page that acts as a front end for

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.