+ Reply to Thread
Results 1 to 18 of 18

MySQL Date Range script

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    MySQL Date Range script

    Hello All,

    I am using Excel with a OBDC connection. I want to only pull data from a table from the past 30 days. I believe the below code should work, but it does not return any data. Any help would be greatly appreciated.

    Please Login or Register  to view this content.
    Thanks,

    Lonney

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: MySQL Date Range script

    MySQL isn't my thing, but it looks right

    What happens when you run it directly against the db through phpmyadmin or the similar?

  3. #3
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: MySQL Date Range script

    Hi,

    is their problem with any sql statement that you try to execute or only with this statement ?
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: MySQL Date Range script

    Oh, actually I don't think paymentdate in your where clause should have quotation marks

  5. #5
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Thanks all!! I am at work right now, but will test when I get home and update. I really appreciate the help!!

    Lonney

  6. #6
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Sorry, I didn't answer the question from xlbiznes. I dont have any issues with any other sql statements that I have. There are also no errors from this statement, just no returned data.

  7. #7
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Sorry, I didn't answer the question from xlbiznes. I dont have any issues with any other sql statements that I have. There are also no errors from this statement, just no returned data.

  8. #8
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: MySQL Date Range script

    Did you try a test sql statement with hard coded date range and see if it fetches any results ?

  9. #9
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Ok - I am not a php guru, so I am likely doing something wrong. I tried to hard code the date as follows:
    Please Login or Register  to view this content.
    No errors, but no data. I also removed the quotation marks around paymentdate to no resolve. UGH!!

  10. #10
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Ok. I made some progress, kind of.

    If I run the below code and use another field which has just the month field which has 2 digits (Example: 11) or another field, the year field, which has 4 digits (example: 2014) the below code works. If I run the same code on the date field, which is formatted as: 11/4/2014, it brings in what appears to be random results. I tried changing the format in Excel to no avail. I also tried different ways to enter the date into the php statement to no avail. Any ideas?

    Please Login or Register  to view this content.
    Thanks everyone!

    Lonney

  11. #11
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Ok - I figured out the issue. The date is stored as a VarChar and not a date. Any ideas on how to approach this?

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: MySQL Date Range script

    Make it a date field?

  13. #13
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Thanks Kyle. Not that easy. I am going to try to use the STR_TO_DATE. Just not sure if Excel will reconize it. I will test wgen I get home.

  14. #14
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: MySQL Date Range script

    Str_to_date would the right approach.

    Here is some sample code for str_to_date from MySQL reference site -> http://dev.mysql.com/doc/refman/5.1/...on_str-to-date

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Excellent - Thankyou!!

  16. #16
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Not having any luck - going to go back at it tonight!

  17. #17
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Update - I am half way there!!
    Here is the issue:

    The paymentyear works. paymentmonth works partially. paymentmonth recognizes single digit months, but does not recognize double digit months. For example: If the paymentmonth is "4" it works. If the paymentmonth is "10", "11" or "12" is does not work. It appears to only be recognizing the first digit, in this case, "1". Any help would be greatly appreciated!!

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: MySQL Date Range script

    Another update:
    If I hard code the paymentmonth in, it works correctly.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how can i download user details from mysql on date basis
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2014, 07:31 AM
  2. MySQL to Excel - Date parameter not detecting
    By f1torque in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-05-2013, 01:36 AM
  3. Range Script
    By allenyeung24 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-15-2011, 10:00 AM
  4. Updating a range of values in a mySQL database
    By billiboy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2008, 07:32 AM
  5. Script out of Range
    By Syed Haider Ali in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2007, 12:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1