Mark Tabor

Mark Tabor

  • 587
  • 2k
  • 460.5k

I have a mysql and in which i set datetime column as nvarcha

Jul 31 2018 3:09 AM
I have mysql and in which i have date column set to varchar instead of date time and it store date in this format 07/17/2018 now i want o use between operator in my query but it does not work because the data type is varchar and between can only be applied on datetime column what to do now
  1. function datevisereport()  
  2. {  
  3. global $tprefix,$con;  
  4. $data='';  
  5. $grandtotal=0;  
  6. $start_date=$_POST['start_date'];  
  7. $to_date =$_POST['end_date'];  
  8. $query="SELECT * FROM plan_voucher WHERE location=".$_SESSION['role']." and created_at between '".$start_date."' and '".$to_date."'";  
  9. $vouceher=mysqli_query($con,$query);  
  10. while($getvoucher=mysqli_fetch_array($vouceher))  
  11. {  
  12. $acamount=0;  
  13. $vdquery='select * from plan_vdetails where vid='.$getvoucher['id'].'';  
  14. $vdetails=mysqli_query($con,$vdquery);  
  15. while($getvdetails=mysqli_fetch_assoc($vdetails))  
  16. {  
  17. if($getvdetails['transtype']=='DR')  
  18. {  
  19. $amountdr=$getvdetails['amount'];  
  20. $amountdcr=0;  
  21. }  
  22. else  
  23. {  
  24. $amountdcr=$getvdetails['amount'];  
  25. $amountdr=0;  
  26. }  
  27. if($getvdetails['isrectify']==1)  
  28. {  
  29. $bgcolor='bgcolor="yellow"';  
  30. }  
  31. else  
  32. {  
  33. $bgcolor='';  
  34. }  
  35. $data.='<tr '.$bgcolor.'>  
  36. <td>'.$getvoucher['created_at'].'</td>  
  37. <td>'.$getvoucher['voucherno'].'</td>  
  38. <td width="40%">'.$getvdetails['glid'].'-'.getSingleValue('accounts','account_no',' where id='.$getvdetails['aid']).'<br>'.$getvdetails['description'].'_'.getSingleValue('employees','fullname',' where id='.$getvdetails['claim_person']).'</td>  
  39. <td>'.$amountdr.'</td>  
  40. <td>'.$amountdcr.'</td>  
  41. <td>'.$getvdetails['rbalance'].'</td>  
  42. </tr>';  
  43. $acamount=$acamount+$amountdr;  
  44. }  
  45. $grandtotal=$grandtotal+$acamount;  
  46. $data.='<tr>  
  47. <td></td>  
  48. <td></td>  
  49. <td></td>  
  50. <td style="border-bottom:1px solid balck;"><strong>'.$acamount.'.00<strong></td>  
  51. <td></td>  
  52. </tr>';  
  53. }  
  54. $data.='<tr>  
  55. <td></td>  
  56. <td></td>  
  57. <td style="border-bottom:1px solid balck;" align="right">Grand Total:</td>  
  58. <td style="border-bottom:1px solid balck;"><strong>'.$grandtotal.'.00<strong></td>  
  59. <td></td>  
  60. </tr>';  
  61. return makepdf($data,$start_date,$to_date);  
  62. }

Answers (8)