Professional Web Applications Themes

mySQL date querying - MySQL

Hi, I'm trying to convert the following query into mySQL, this currently working with MS SQL although not with mySQL. SET DATEFORMAT dmy declare d datetime set d = '01/12/2007' select * from matrix.subscriptions where d between startdate and enddate The above query searches a date between two fields. (startdate and enddate) Anyone got any idea how this can be done within mySQL Thanks for your help David...

  1. #1

    Default mySQL date querying

    Hi,

    I'm trying to convert the following query into mySQL, this currently
    working with MS SQL although not with mySQL.

    SET DATEFORMAT dmy declare d datetime set d = '01/12/2007' select *
    from matrix.subscriptions where d between startdate and enddate

    The above query searches a date between two fields. (startdate and
    enddate)

    Anyone got any idea how this can be done within mySQL

    Thanks for your help

    David

    davidjohnlong@googlemail.com Guest

  2. #2

    Default Re: mySQL date querying

    On 5 Feb, 13:05, "com"
    <com> wrote: 

    Reformat the date to the ISO one used by MySQL.

    Captain Guest

  3. #3

    Default Re: mySQL date querying

    "com" <com> wrote: 

    SET d = STR_TO_DATE('01/12/2007', '%m/%d/%Y');
    SELECT ... WHERE d BETWEEN startdate AND enddate;

    RTFM on STR_TO_DATE() and friends:
    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html


    XL
    --
    Axel Schwenke, Support Engineer, MySQL AB

    Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/
    MySQL User Forums: http://forums.mysql.com/
    Axel Guest

  4. #4

    Default Re: mySQL date querying

    On 5 Feb, 15:31, Axel Schwenke <de> wrote: 


    >
    > SET d = STR_TO_DATE('01/12/2007', '%m/%d/%Y');
    > SELECT ... WHERE d BETWEEN startdate AND enddate;
    >
    > RTFM on STR_TO_DATE() and friends:http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
    >
    > XL
    > --
    > Axel Schwenke, Support Engineer, MySQL AB
    >
    > Online User Manual:http://dev.mysql.com/doc/refman/5.0/en/
    > MySQL User Forums: http://forums.mysql.com/[/ref]

    Surely that'd be
    SET d = STR_TO_DATE('01/12/2007', '%d/%m/%Y');
    SELECT ... WHERE d BETWEEN startdate AND enddate;

    Or more concisely:
    SELECT ... WHERE STR_TO_DATE('01/12/2007', '%d/%m/%Y') BETWEEN
    startdate AND enddate;

    Captain Guest

Similar Threads

  1. Weird problem querying mysql
    By Don Vaillancourt in forum MySQL
    Replies: 4
    Last Post: February 14th, 03:39 AM
  2. Querying a date closest to today
    By Explorer5 in forum Coldfusion Database Access
    Replies: 2
    Last Post: February 24th, 07:53 PM
  3. PHP Date into MySQL
    By Sue Roussie in forum PHP Development
    Replies: 1
    Last Post: February 13th, 10:11 PM
  4. date for mysql
    By Diana in forum PHP Development
    Replies: 2
    Last Post: October 17th, 01:40 PM
  5. date mysql
    By --==Pyrix==-- in forum PHP Development
    Replies: 1
    Last Post: September 7th, 11:09 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139