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..

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

报告相同问题?

悬赏问题

  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错