格式化数据库中的日期数字

发布于 2024-10-08 19:06:27 字数 600 浏览 0 评论 0原文

不确定我是否应该编辑这个问题,或者只是在不同的帖子中提出另一个问题。我很难做与我最初要求相反的事情。如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

故事和酒 2024-10-15 19:06:27

您正在寻找日期函数:

$meeting_date = date('Y-m-d', strtotime($time_date_data));
$meeting_time = date('H:i', strtotime($time_date_data));

对于 $time_date_data = '2010-08-24 20:00:00.000',您将得到:

$meeting_date = '2010-08-24';
$meeting_time = '20:00';

您可以通过更改 date()第一个参数来更改格式代码> 根据文档...

You're looking for the date function:

$meeting_date = date('Y-m-d', strtotime($time_date_data));
$meeting_time = date('H:i', strtotime($time_date_data));

For $time_date_data = '2010-08-24 20:00:00.000', you'll get:

$meeting_date = '2010-08-24';
$meeting_time = '20:00';

You can change the format by changing the first argument to date() according to the docs...

饭团 2024-10-15 19:06:27

这里有两个选择。您可以在 SQL Server 端或应用程序端执行此操作。

对于 SQL:如果您只需要日期(格式为 YYYY/MM/DD),请执行以下操作:

SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD]

如果您只需要时间(格式为 HH:MM:SS),请执行以下操作:

SELECT CONVERT(VARCHAR(8), GETDATE(), 108)  

或者,您可以在 PHP 中使用“date”函数来完成这一切,例如:

$theDate = date("YYYY/MM/DD", strtotime($theFullDate))
$theTime = date("HH:MM:SS", strtotime($theFullDate))

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:

SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD]

If you want the time only, in format HH:MM:SS, do this:

SELECT CONVERT(VARCHAR(8), GETDATE(), 108)  

Alternatively, you can do this all in PHP by using the "date" function, something like:

$theDate = date("YYYY/MM/DD", strtotime($theFullDate))
$theTime = date("HH:MM:SS", strtotime($theFullDate))
坏尐絯 2024-10-15 19:06:27

尝试:

$stamp=strtotime("2010-08-24 20:00:00.000");
$date=date("Y-m-d",$stamp);
$time=date("H:i:s",$stamp);

或:

list($date,$time)=explode(" ","2010-08-24 20:00:00.000");

Try:

$stamp=strtotime("2010-08-24 20:00:00.000");
$date=date("Y-m-d",$stamp);
$time=date("H:i:s",$stamp);

or:

list($date,$time)=explode(" ","2010-08-24 20:00:00.000");
谁的年少不轻狂 2024-10-15 19:06:27
$meeting_date = substr($time_date_data, 0, -13);

$meeting_time = substr($time_date_data,11); 
$meeting_date = substr($time_date_data, 0, -13);

$meeting_time = substr($time_date_data,11); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文