从数据库格式化日期数字 [英] Format Date Number from Database

查看:34
本文介绍了从数据库格式化日期数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我是否应该编辑这个问题,或者只是在不同的帖子中提出另一个问题.我很难做我最初要求的相反的事情.如何在 php.ini 中获取日期编号".我想将当前日期编号分配给一个变量,以便我可以在查询中使用它来比较数据库中已有的内容.

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.

我看不到 SQL Server 数据库但我使用 ODBC 连接到它和 PHP 在 Linux 机器上.有人告诉我字段meeting_start"是一个日期编号".当我得到的价值meeting_start"格式看起来像这样.

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);

推荐答案

您正在寻找 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));

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

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

您可以根据文档将第一个参数更改为 date() 来更改格式...

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

这篇关于从数据库格式化日期数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆