doutang7383 2012-03-29 10:48
浏览 50
已采纳

格式化日期时遇到问题

I have a datepicker on my site. When you select a date, it displays as dd/mm/yyyy

In order to search the date, the mysql db has to be similar to it

But it looks like yyyy-mm-dd H:i:s which I cant search for

Edit I also wanted to search between two dates but was having difficulty since the two formats were different

My question was, how would I format my search function to find a similarity from the datepicker and the mysql datetime?

Here's what I have so far (date_avialable is the column name)

$sql = mysql_query("SELECT * FROM search_v WHERE Currency='$currency' AND rout_to='$sto' AND

rout_from='$sfrom' AND DATE_FORMAT(date_avialable,'%Y-%m-%d') BETWEEN '$sfromda' AND 'stoda' LIMIT 10") or die(mysql_error()) ;
while ( $runrows = mysql_fetch_array($sql))

I wanted to do something like this

$mysqldate = date( 'Y-m-d H:i:s', $phpdate );
$phpdate = strtotime( $mysqldate );

But didn't know how to call that into the db

  • 写回答

1条回答 默认 最新

  • duanneng2014 2012-03-29 10:59
    关注

    If your specification in question are correct try (to change) this in your code..

    AND DATE_FORMAT(date_avialable,'%d-%m-%Y')
    

    or separate your PICKER date to strings shown bellow on the left and do this

    AND ($calendarday) = date_format(from_unixtime(date_avialable),'%d')
    AND ($calendarmonth) = date_format(from_unixtime(date_avialable),'%m')
    AND ($calendaryear) = date_format(from_unixtime(date_avialable),'%Y')
    

    If that aint gonna work, please go to phpmyadmin, and try to tell us what is the format of date in your "date_avialable" row. Is it a unix timestamp or d-m-Y or similar..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题