格式化数据库中的日期数字
不确定我是否应该编辑这个问题,或者只是在不同的帖子中提出另一个问题。我很难做与我最初要求相反的事情。如何在 php.ini 中获取“日期编号”?我想将当前日期编号分配给一个变量,以便我可以在查询中使用它来比较数据库中已有的内容。
我看不到 SQL Server 数据库 但我使用 ODBC 连接到它 以及 Linux 机器上的 PHP。有人告诉我 字段“meeting_start”是 “日期号码”。当我得到的值 “meeting_start”的格式看起来 像这样。
<前><代码>2010-08-24 20:00:00.000我需要日期和时间,但是对于 我的职能的不同部分。是 有一种方法可以提取数据 日期并保存到变量中 然后提取该时间的数据并 保存到不同的变量。下面是 我试图尝试一下。
$time_date_data = "2010-08-24 20:00:00.000" $meeting_date = get_date($time_date_data); $meeting_time = get_time($time_date_data);
Not sure if I should edit this question or just ask another question in a different post. I am having a hard time doing the reverse of what I originally asked. How do I get the "date number" in php. I want to assign the current date number to a variable to so I can use it in my query to compare what is already in the database.
I can not see the SQL Server database
but I am connecting to it using ODBC
and PHP on a Linux box. I was told
that the field "meeting_start" was a
"Date Number". When I get the value of
the "meeting_start" the format looks
like this.2010-08-24 20:00:00.000
I need both the date and time but for
different parts of my function. Is
there a way to extract the data for
the date and save to a variable and
then extract the data for the time and
save to a different variable. Below is
me trying to take a stab at it.$time_date_data = "2010-08-24 20:00:00.000" $meeting_date = get_date($time_date_data); $meeting_time = get_time($time_date_data);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在寻找
日期
函数:对于
$time_date_data = '2010-08-24 20:00:00.000'
,您将得到:您可以通过更改
date()
第一个参数来更改格式代码> 根据文档...You're looking for the
date
function:For
$time_date_data = '2010-08-24 20:00:00.000'
, you'll get:You can change the format by changing the first argument to
date()
according to the docs...这里有两个选择。您可以在 SQL Server 端或应用程序端执行此操作。
对于 SQL:如果您只需要日期(格式为 YYYY/MM/DD),请执行以下操作:
如果您只需要时间(格式为 HH:MM:SS),请执行以下操作:
或者,您可以在 PHP 中使用“date”函数来完成这一切,例如:
Two options here. You can do it either on the SQL Server side or the application side.
For SQL: If you want the date only, in format YYYY/MM/DD, do this:
If you want the time only, in format HH:MM:SS, do this:
Alternatively, you can do this all in PHP by using the "date" function, something like:
尝试:
或:
Try:
or: