Jump to content

string not converted to date


Karyna

Recommended Posts

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

        

        

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.