Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • MYSQL, PHP :- Query Concatenating Fields To Make Date And Running Between Query On It

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 455
    Comment on it

    Recently, I faced a problem when the date was saved in different fields month, year and date. I need to club all these fields together and run a between query on it.

    Another issue which was there was that Date has '0' contacted if the value is less than 10 and if new date created do not follow this pattern the result does not come out correct. So, I used LPAD of MYSQL which fills zero correspondingly.

    SQL QUERY :-

    SELECT stamp, COUNT(*) AS cnt FROM diary WHERE (CONCAT (CONCAT_WS( '-', yearstart, LPAD( monthstart, 2, '0' ) + 1 , LPAD( datestart, 2, '0' ) ) , ' 00:00:00') BETWEEN '{$data['start_date']} 00:00:00' AND '{$data['end_date']} 23:59:59' ) and userid = {$data['userid']} and status = 1 GROUP BY stamp ";
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: