遇到格式不正确的数值 [英] A non well formed numeric value encountered
问题描述
我有一个表单将两个日期(开始和结束)传递给一个 PHP 脚本,该脚本会将这些日期添加到数据库中.我在验证这一点时遇到了问题.我不断收到以下错误
I have a form that passes two dates (start and finish) to a PHP script that will add those to a DB. I am having problems validating this. I keep getting the following errors
遇到格式不正确的数值
这是我使用以下内容的时候
This is when I use the following
date("d",$_GET['start_date']);
但是当我按照许多网站的建议使用 strtotime() 函数时,我得到 1/1/1970 的 unix 时间戳日期.任何想法如何获得正确的日期?
But when I use the strtotime() function as advised by many sites I get a unix timestamp date of 1/1/1970. Any ideas how I can get the correct date?
推荐答案
因为你要传递一个字符串作为日期函数的第二个参数,它应该是一个整数.
Because you are passing a string as the second argument to the date function, which should be an integer.
字符串日期(字符串 $format [, int $timestamp = time() ] )
string date ( string $format [, int $timestamp = time() ] )
尝试strtotime,它将解析任何英文文本日期时间描述转换成 Unix 时间戳(整数):
date("d", strtotime($_GET['start_date']));
这篇关于遇到格式不正确的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!