我正在使用php / mysql.when我正在尝试在两个日期之间获取数据一切正常。但是当我想在两个月之间获取数据时,例如:31-01-2014和03- 02-2014它没有工作,并给出了空的结果set.its workign fien一个月。
这是我的问题:
$sql1="select
reg.id,
payonline.regno as FORM_NO,
payonline.paydate as DATE,
reg.stufname as FIRSTNAME,
reg.stumname as MIDDLENAME,
reg.stulname as LASTNAME,
reg.stuemail as EMAIL,
DATE_FORMAT(reg.studob,'%d-%m-%Y') as DOB,
reg.stugender as GENDER,
reg.stumobile as MOBILE,
prg.paymentmode as PAYMENTMODE,
prg.examdate as TESTDATE,
prg.examcenter as EXAM_CENTER,
prg.hostel as HOSTEL,
prg.coursetype as PRG_TYPE,
prg.campus1 as CAMPUS1,
prg.course1 as PRG_NAME1,
prg.campus2 as CAMPUS2,
prg.course2 as PRG_NAME2,
prg.pgd_intrested as pgd_intrested,
prg.pgd_course1 as pgd_course1,
prg.pgd_campus1 as pgd_campus1,
prg.pgd_course2 as pgd_course2,
prg.pgd_campus2 as pgd_campus2,
family.stufname as FATHERNAME,
family.stufoccupation as FATHER_OCCUPATION,
family.stufmobile as FATHER_MOBILE,
family.stufspecify as FATHER_SPECIFY,
family.stufincome as FATHER_INCOME,
family.stufemail as FATHER_EMAIL,
family.stumname as MOTHERNAME,
family.stumoccupation as MOTHER_OCCUPATION,
family.stummobile as MOTHER_MOBILE,
family.stumspecify as MOTHER_SPECIFY,
family.stumincome as MOTHER_INCOME,
family.stumemail as MOTHER_EMAIL,
family.guardianname as GUARDIAN,
family.guardianaddress as GUARDIAN_ADDRESS,
family.guardianphone as GUARDIAN_PHONE,
address.presentaddress as PRESENT_ADDRESS,
address.presentcity as PRESENT_CITY,
address.presentstate as PRESENT_STATE,
address.presentpin as PRESENT_PIN,
address.presentcountry as PRESENT_COUNTRY,
address.presentphone as PRESENT_PHONE,
address.permanentaddress as PERMANENT_ADDRESS,
address.permanentcity as PERMANENT_CITY,
address.permanentstate as PERMANENT_STATE,
address.permanentpin as PERMANENT_PIN,
address.permanentcountry as PERMANENT_COUNTY,
address.permanentphone as PERMANENT_PHONE,
address.mailingaddress as MAILING_ADDRESS,
edu.10_streamname as 10_STREAM,
edu.10_institutename as 10_INSTITUTE,
edu.10_year as 10_YEAR,
edu.10_board as 10_BOARD,
edu.10_percentage as 10_PERCENTAGE,
edu.10_subjects as 10_SUBJECTS,
edu.12_streamname as 12_STREAM,
edu.12_institutename as 12_INSTITUTE,
edu.12_year as 12_YEAR,
edu.12_board as 12_BOARD,
edu.12_percentage as 12_PERCENTAGE,
edu.12_subjects as 12_SUBJECTS,
edu.g_streamname as G_STREAM,
edu.g_institutename as G_INSTITUTE,
edu.g_year as G_YEAR,
edu.g_university as G_UNIVERSITY,
edu.g_percentage as G_PERCENTAGE,
edu.g_subjects as G_SUBJECTS,
edu.pg_streamname as PG_STREAM,
edu.pg_institutename as PG_INSTITUTE,
edu.pg_year as PG_YEAR,
edu.pg_university as PG_UNIVERSITY,
edu.pg_percentage as PG_PERCENTAGE,
edu.pg_subjects as PG_SUBJECTS,
edu.m_streamname as M_STREAM,
edu.m_institutename as M_Institute,
edu.m_year as M_YEAR,
edu.m_university as M_UNIVERSITY,
edu.m_percentage as M_PERCENTAGE,
edu.m_subjects as M_SUBJECTS,
ext.stuexamcenter as EXAMCENTER,
ext.activities as ACTIVITES,
ext.awards as AWARDS,
ext.options as OPTIONS,
ext.mat as MAT_YEAR,
ext.matscore as MAT_SCORE,
ext.cat as CAT_YEAR,
ext.catscore as CAT_SCORE,
ext.gmat as GMAT_YEAR,
ext.gmatscore as GMAT_SCORE,
work.job1 as JOB1,
work.org1 as ORG1,
work.designation1 as DESIGNATION1,
work.sdate1 as START_DATE1,
work.edate1 as END_DATE1,
work.job2 as JOB2,
work.org2 as ORG2,
work.designation2 as DESIGNATION2,
work.sdate2 as START_DATE2,
work.edate2 as END_DATE2,
work.job3 as JOB3,
work.org3 as ORG3,
work.designation3 as DESIGNATION3,
work.sdate3 as START_DATE3,
work.edate3 as END_DATE3,
dd.ddno as DD_NO,
dd.dddate as DD_DATE,
dd.ddbank as DD_BANK,
payonline.receiptno as RECEIPT_NO,
payonline.txnno as TRANSACTION_NO,
payonline.status as STATUS,
payonline.amount as AMOUNT
from registration as reg
join programme as prg on reg.id=prg.stuid
join family on reg.id=family.stuid
join address on reg.id=address.stuid
join education as edu on reg.id=edu.stuid
join extradetail as ext on reg.id=ext.stuid
join workexperience as work on reg.id=work.stuid
join demanddraft as dd on reg.id=dd.stuid
join payonline on reg.id=payonline.stuid where payonline.status='success' and payonline.paydate >= '".$_POST['date1']."' and payonline.paydate <= '".$_POST['date2']."'";
答案 0 :(得分:1)
在我看来,最好的解决方案是以DATE或DATETIME或Timestamp格式保存日期。
但在您的情况下,如THIS LINK中所述,您可以在条件中使用STR_TO_DATE和LEFT将其转换为查询中的DATETIME:
STR_TO_DATE(LEFT(payonline.paydate,LOCATE('',payonline.paydate)),'%m /%d /%Y')在'2010-07-28'和'2010-07-29'之间< / p>