Karyna Posted May 27, 2020 Share Posted May 27, 2020 PLEASEEE no matter what i do... datepicker always post the dates as string i do whatever ways know convert string to date but no way!! how convert string to date so i can sarch in a mysql table... tnx in advanced <!--HTML--> <div class="control-group"> <label class="control-label">from</label> <div class="controls input-append date form_date" data-date="" data-date-format='yyyy/mm/dd' data-link-format="yyyy/mm/dd"> <input size="16" type="text" value="" id="from" name="from"> <span class="add-on"><i class="icon-th"></i></span> </div> <input type="hidden" id="d" value="" /><br/> </div> <div class="control-group"> <label class="control-label">tto</label> <div class="controls input-append date form_date" data-date="" data-date-format='yyyy/mm/dd' data-link-format="yyyy/mm/dd"> <input size="16" type="text" value="" id="tto" name="tto"> <span class="add-on"><i class="icon-th"></i></span> </div> <input type="hidden" id="h" value="" /><br/> </div> <div class="card-body"> <button type="submit" class="btn btn-secondary">search...</button> </div> <!--PHP--> $yfromx=$_POST['from'] ; $yuntilly=$_POST['untill'] ; $yfroma=str_replace(" ","/","$yfromx"); $yuntillb=str_replace(" ","/","$yuntilly"); $t1=gettype ( $yfromx ) ; $t2=gettype ( $yuntilly ) ; $yfrom=date('Y/m/d', '$yfroma'); $yuntill=date('Y/m/d', '$yuntillb'); $t3=gettype ( $yfrom ) ; $t4=gettype ( $yuntill ) ; echo $yfroma.' | '.$yuntillb.' | '.$t1.' | '. $t2.' | '.$t3.' | '. $t4; //SELECT username FROM oc_calendar WHERE start_date between '$from' AND '$to' $queryfebus = "SELECT distintc FROM glamm_pedidos WHERE fecha_folio between '$yfrom' AND '$yuntill';"; //$queryfolb = "SELECT *M glamm_pedidos WHERE procesado='$yfoliox' or folio='$yfoliox' or nombre like '%$yfoliox%' or mail like '%$yfoliox%';"; $resultfebus = mysqli_query($con,$queryfebus) or mysqli_error($con); blah blah Quote Link to comment https://forums.phpfreaks.com/topic/310856-string-not-converted-to-date/ Share on other sites More sharing options...
Barand Posted May 27, 2020 Share Posted May 27, 2020 Databases like "yyyy-mm-dd" format for dates Quote Link to comment https://forums.phpfreaks.com/topic/310856-string-not-converted-to-date/#findComment-1578427 Share on other sites More sharing options...
Phi11W Posted May 29, 2020 Share Posted May 29, 2020 On 5/27/2020 at 5:52 PM, Karyna said: how convert string to date so i can sarch in a mysql table PHP has a handy strtotime() function that does exactly that. Since you're [still] building your SQL dynamically, you do need to worry about how to format the Date Literals in your SQL. Ideally, you should use Parameterised Queries that will take care of this for you but, as you're not there yet, you need to format the Date literal to ensure no ambiguity when passing it to the database. $yfrom = date( 'Y-m-d', $dateTimeValue ); $yuntil = date( 'Y-m-d', $dateTimeValue ); $queryfebus = "SELECT x, y, z FROM glamm_pedidos WHERE fecha_folio BETWEEN '$yfrom' AND '$yuntill' "; Also, make sure that the columns in your database tables really are a Date Data Type. All too often, we see people complaining about the "format" of the Dates in the database tables. One of the "Rules" or Relational Databases: Dates have no format. None that you or I need to worry about, anyway. If you think that your Dates have the "wrong format", then the chances are that you actually have Character data that just happens to look like Dates. That's never a Good Thing and will cause you all kinds of grief. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/310856-string-not-converted-to-date/#findComment-1578470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.