Câu hỏi thường gặp về ngày/giờ PHP. Làm cách nào để tạo ngày ở định dạng thích hợp để chèn trường Dấu thời gian SQL vào cơ sở dữ liệu SQL?
Ghi chú. Bạn có thể không cần tạo ngày PHP
Trước hết, bạn có thể không cần tạo ngày tháng trong PHP như thế này. Nếu bạn đang sử dụng PHP cũ thuần túy và cơ sở dữ liệu như MySQL, bạn có thể sử dụng hàm SQL
2019-10-02 18:41:1719 để chèn dữ liệu vào trường dấu thời gian SQL như thế này
INSERT INTO projects [user_id, name, last_updated, date_created] VALUES [5, 'alvin', now[], now[]];
Tôi vừa thử nghiệm điều này với PHP và MySQL, và nó hoạt động tốt. Vì vậy, đó là một cách để điền vào trường dấu thời gian SQL trong truy vấn SQL INSERT
Tạo biến dấu thời gian PHP
Tuy nhiên, nếu bạn muốn thực hiện tất cả điều này bằng PHP [hoặc cần, tùy thuộc vào khung công tác bạn đang làm việc], bạn có thể lấy ngày và giờ hiện tại ở định dạng phù hợp chỉ bằng cách sử dụng PHP, như sau
$timestamp = date['Y-m-d H:i:s'];
Nếu bạn in nó ra, trường
2019-10-02 18:41:1720 của bạn bây giờ sẽ chứa nội dung như thế này
2019-10-02 18:41:17
Sau đó, bạn có thể sử dụng chuỗi dấu thời gian được định dạng này trong phần chèn PHP MySQL
Ghi chú. Cảm ơn những người bình luận bên dưới đã đề xuất sử dụng
2019-10-02 18:41:1721 thay vì2019-10-02 18:41:1722
Ví dụ về CHÈN SQL Drupal 7 với Dấu thời gian
Mặc dù đây không phải là câu lệnh
$timestamp = date['Y-m-d H:i:s'];0 PHP/MySQL tiêu chuẩn có sẵn, nhưng đây là giao diện của một truy vấn SQL
$timestamp = date['Y-m-d H:i:s'];0 khi tôi sử dụng câu lệnh này với Drupal 7
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];
Như bạn có thể thấy trong các dòng tôi đã in đậm, tôi đang chèn biến dấu thời gian PHP của mình vào hai trường SQL
Nhận dấu thời gian cho một số ngày và giờ khác
Lưu ý rằng hàm PHP
$timestamp = date['Y-m-d H:i:s'];2 mặc định là ngày và giờ hiện tại, đây chính xác là những gì tôi cần cho mục đích của mình ở đây. Nếu bạn cần tạo trường dấu thời gian được định dạng cho một số ngày và giờ khác, bạn có thể làm như thế này
$timestamp = date['Y-m-d H:i:s', mktime[0, 0, 0, 7, 1, 2000]];
Dưới đây là một số ví dụ PHP
$timestamp = date['Y-m-d H:i:s'];3 khác
$tomorrow = mktime[0, 0, 0, date["m"] , date["d"]+1, date["Y"]]; $lastmonth = mktime[0, 0, 0, date["m"]-1, date["d"], date["Y"]]; $nextyear = mktime[0, 0, 0, date["m"], date["d"], date["Y"]+1];
Tôi đã lấy những ví dụ đó từ trang ngày PHP. Vui lòng xem trang đó để biết thêm thông tin về cách tạo ngày và giờ khác [tôi hầu như chỉ lo lắng về "bây giờ" vào lúc này]
Chèn dấu thời gian PHP SQL
Tôi hy vọng những ví dụ về dấu thời gian này hữu ích. Như bạn đã thấy, thông thường bạn chỉ có thể sử dụng hàm 'NOW[]' của SQL để chèn vào trường dấu thời gian SQL, nhưng nếu vì lý do nào đó mà cách đó không hoạt động, bạn cũng có thể tạo trường dấu thời gian ở định dạng phù hợp bằng cách sử dụng
Ngày Giờ. Hàm add[] là một hàm có sẵn trong PHP được sử dụng để thêm một lượng thời gian [ngày, tháng, năm, giờ, phút và giây] vào đối tượng DateTime đã cho
cú pháp
- Phong cách hướng đối tượng.
$timestamp = date['Y-m-d H:i:s'];
0 - phong cách thủ tục.
$timestamp = date['Y-m-d H:i:s'];
1
Thông số. Hàm này sử dụng hai tham số như đã đề cập ở trên và được mô tả bên dưới
- đối tượng $. Nó chỉ định đối tượng DateTime được trả về bởi hàm date_create[]. Hàm này trả về một đối tượng DateTime mới
- $khoảng. Tham số này giữ đối tượng DateInterval
Giá trị trả về. Hàm này trả về đối tượng DateTime mới sau khi thay đổi thành công hoặc Sai khi thất bại
Sự cố này mô tả định dạng ngày để chèn ngày vào cơ sở dữ liệu MySQL. MySQL truy xuất và hiển thị các giá trị DATETIME trong 'YYYY-MM-DD HH. MM. định dạng SS. Ngày chỉ có thể được lưu trữ ở định dạng này. Tuy nhiên, nó có thể được sử dụng với bất kỳ chức năng định dạng thời gian nào để thay đổi và hiển thị nó.
Khi viết một truy vấn trong MySQL bằng PHP, khả năng ứng dụng của nó sẽ được kiểm tra trên cơ sở của chính MySQL. Vì vậy, hãy sử dụng định dạng ngày và giờ mặc định do MySQL cung cấp. e. 'YYYY-MM-DD'
ví dụ
$timestamp = date['Y-m-d H:i:s'];2
Truy vấn MySQL để tạo DataBase
$timestamp = date['Y-m-d H:i:s'];3
ví dụ 1. Chương trình PHP để tạo cơ sở dữ liệu và bảng
php
2019-10-02 18:41:1723
2019-10-02 18:41:1724
2019-10-02 18:41:1725
$timestamp = date['Y-m-d H:i:s'];30____131
$timestamp = date['Y-m-d H:i:s'];32
$timestamp = date['Y-m-d H:i:s'];33
$timestamp = date['Y-m-d H:i:s'];30
$timestamp = date['Y-m-d H:i:s'];35____132
$timestamp = date['Y-m-d H:i:s'];37
$timestamp = date['Y-m-d H:i:s'];30
$timestamp = date['Y-m-d H:i:s'];39
$timestamp = date['Y-m-d H:i:s'];32
2019-10-02 18:41:1751
$timestamp = date['Y-m-d H:i:s'];30
2019-10-02 18:41:1753____132
2019-10-02 18:41:1724
2019-10-02 18:41:1756
2019-10-02 18:41:1757
2019-10-02 18:41:1758
2019-10-02 18:41:1725
$timestamp = date['Y-m-d H:i:s'];20
$timestamp = date['Y-m-d H:i:s'];33
$timestamp = date['Y-m-d H:i:s'];20
$timestamp = date['Y-m-d H:i:s'];37
$timestamp = date['Y-m-d H:i:s'];20
2019-10-02 18:41:1751
$timestamp = date['Y-m-d H:i:s'];26
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];28
$timestamp = date['Y-m-d H:i:s'];29
$timestamp = date['Y-m-d H:i:s'];10
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];12
$timestamp = date['Y-m-d H:i:s'];13
$timestamp = date['Y-m-d H:i:s'];14
$timestamp = date['Y-m-d H:i:s'];15
$timestamp = date['Y-m-d H:i:s'];16
$timestamp = date['Y-m-d H:i:s'];17
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:1724
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];00
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];02
_______413____504
_______413____506
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];07
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];29
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];90
2019-10-02 18:41:1757____320
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];94
$timestamp = date['Y-m-d H:i:s'];13
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];96
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];97____132
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:17230
2019-10-02 18:41:17231
$timestamp = date['Y-m-d H:i:s'];13
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];96
2019-10-02 18:41:17234
2019-10-02 18:41:17235
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];26
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:1724
2019-10-02 18:41:17240
2019-10-02 18:41:17241____257____326
2019-10-02 18:41:17244
đầu ra.
2019-10-02 18:41:175
ví dụ 2. Chương trình PHP để chèn ngày vào bảng
php
2019-10-02 18:41:1723
2019-10-02 18:41:1724
2019-10-02 18:41:1725
$timestamp = date['Y-m-d H:i:s'];30____131
$timestamp = date['Y-m-d H:i:s'];32
$timestamp = date['Y-m-d H:i:s'];33
$timestamp = date['Y-m-d H:i:s'];30
$timestamp = date['Y-m-d H:i:s'];35____132
$timestamp = date['Y-m-d H:i:s'];37
$timestamp = date['Y-m-d H:i:s'];30
$timestamp = date['Y-m-d H:i:s'];39
$timestamp = date['Y-m-d H:i:s'];32
2019-10-02 18:41:1751
$timestamp = date['Y-m-d H:i:s'];30
2019-10-02 18:41:1753____132
2019-10-02 18:41:1724
2019-10-02 18:41:1756
2019-10-02 18:41:1757
2019-10-02 18:41:1758
2019-10-02 18:41:1725
$timestamp = date['Y-m-d H:i:s'];20
$timestamp = date['Y-m-d H:i:s'];33
$timestamp = date['Y-m-d H:i:s'];20
$timestamp = date['Y-m-d H:i:s'];37
$timestamp = date['Y-m-d H:i:s'];20
2019-10-02 18:41:1751
$timestamp = date['Y-m-d H:i:s'];26
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];28
$timestamp = date['Y-m-d H:i:s'];29
$timestamp = date['Y-m-d H:i:s'];10
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];12
$timestamp = date['Y-m-d H:i:s'];13
$timestamp = date['Y-m-d H:i:s'];14
$timestamp = date['Y-m-d H:i:s'];15
$timestamp = date['Y-m-d H:i:s'];16
$timestamp = date['Y-m-d H:i:s'];17
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];328
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
$timestamp = date['Y-m-d H:i:s'];330
$timestamp = date['Y-m-d H:i:s'];331
$timestamp = date['Y-m-d H:i:s'];332
$timestamp = date['Y-m-d H:i:s'];333
$timestamp = date['Y-m-d H:i:s'];334
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];29
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];90
2019-10-02 18:41:1757____320
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];94
$timestamp = date['Y-m-d H:i:s'];13
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];96
$timestamp = date['Y-m-d H:i:s'];344
$timestamp = date['Y-m-d H:i:s'];32
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:17230
2019-10-02 18:41:17231
$timestamp = date['Y-m-d H:i:s'];13
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];96
$timestamp = date['Y-m-d H:i:s'];351
$timestamp = date['Y-m-d H:i:s'];352
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
$timestamp = date['Y-m-d H:i:s'];352
$timestamp = date['Y-m-d H:i:s'];355
2019-10-02 18:41:17235
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];26
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:1724
2019-10-02 18:41:17240
2019-10-02 18:41:17241____257____326
2019-10-02 18:41:17244
đầu ra.
$timestamp = date['Y-m-d H:i:s'];2
Ví dụ 3. Ví dụ này được sử dụng để hiển thị hàng nào được tạo vào ngày 2018-12-05. Sử dụng truy vấn sau để hiển thị kết quả.
Cột created_at không chỉ chứa ngày tháng mà còn cả thời gian. Vì vậy, nó sẽ hiển thị thông báo lỗi.
$timestamp = date['Y-m-d H:i:s'];1
đầu ra
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];0
Truy vấn đúng. Để sửa lại, hãy sử dụng hàm DATE như sau
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];9
php
2019-10-02 18:41:1723
2019-10-02 18:41:1724
2019-10-02 18:41:1725
$timestamp = date['Y-m-d H:i:s'];30____131
$timestamp = date['Y-m-d H:i:s'];32
$timestamp = date['Y-m-d H:i:s'];33
$timestamp = date['Y-m-d H:i:s'];30
$timestamp = date['Y-m-d H:i:s'];35____132
$timestamp = date['Y-m-d H:i:s'];37
$timestamp = date['Y-m-d H:i:s'];30
$timestamp = date['Y-m-d H:i:s'];39
$timestamp = date['Y-m-d H:i:s'];32
2019-10-02 18:41:1751
$timestamp = date['Y-m-d H:i:s'];30
2019-10-02 18:41:1753____132
2019-10-02 18:41:1724
2019-10-02 18:41:1756
2019-10-02 18:41:1757
2019-10-02 18:41:1758
2019-10-02 18:41:1725
$timestamp = date['Y-m-d H:i:s'];20
$timestamp = date['Y-m-d H:i:s'];33
$timestamp = date['Y-m-d H:i:s'];20
$timestamp = date['Y-m-d H:i:s'];37
$timestamp = date['Y-m-d H:i:s'];20
2019-10-02 18:41:1751
$timestamp = date['Y-m-d H:i:s'];26
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];28
$timestamp = date['Y-m-d H:i:s'];29
$timestamp = date['Y-m-d H:i:s'];10
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];12
$timestamp = date['Y-m-d H:i:s'];13
$timestamp = date['Y-m-d H:i:s'];14
$timestamp = date['Y-m-d H:i:s'];15
$timestamp = date['Y-m-d H:i:s'];16
$timestamp = date['Y-m-d H:i:s'];17
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:1724
2019-10-02 18:41:17509
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
2019-10-02 18:41:17511
2019-10-02 18:41:17512
2019-10-02 18:41:17513
2019-10-02 18:41:17514
2019-10-02 18:41:17515
2019-10-02 18:41:17516
2019-10-02 18:41:1724
2019-10-02 18:41:17518
2019-10-02 18:41:17519
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];20
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
2019-10-02 18:41:17523
2019-10-02 18:41:1724
$timestamp = date['Y-m-d H:i:s'];29
$timestamp = date['Y-m-d H:i:s'];15
2019-10-02 18:41:17518
$timestamp = date['Y-m-d H:i:s'];12
$timestamp = date['Y-m-d H:i:s'];13
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];96
2019-10-02 18:41:17518
$timestamp = date['Y-m-d H:i:s'];32
2019-10-02 18:41:17533
2019-10-02 18:41:17534
2019-10-02 18:41:17230
2019-10-02 18:41:17231
$timestamp = date['Y-m-d H:i:s'];13
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];96
$timestamp = date['Y-m-d H:i:s'];351
$timestamp = date['Y-m-d H:i:s'];352
$project = new stdClass[]; $project->user_id = get_user_id[]; $project->project_count_type = $form_state['values']['type']; $project->name = $form_state['values']['name']; $project->description = $form_state['values']['description']; # get the current time in the proper format for a sql timestamp field $timestamp = date['Y-m-d H:i:s']; # new drupal 7 style insert $id = db_insert['projects'] ->fields[array[ 'user_id' => $project->user_id, 'project_count_type' => $project->project_count_type, 'name' => $project->name, 'description' => $project->description, 'last_updated' => $timestamp, 'date_created' => $timestamp ]] ->execute[];01
$timestamp = date['Y-m-d H:i:s'];352
$timestamp = date['Y-m-d H:i:s'];355
2019-10-02 18:41:17235
2019-10-02 18:41:1757
$timestamp = date['Y-m-d H:i:s'];26
$timestamp = date['Y-m-d H:i:s'];18
2019-10-02 18:41:1724
2019-10-02 18:41:17240
2019-10-02 18:41:17241____257____326
2019-10-02 18:41:17244
Đầu ra.
Để lấy năm, quý, tháng, tuần, ngày, giờ, phút và giây từ một giá trị DATETIME, hãy sử dụng các hàm như trong câu lệnh sau.
GIỜ[@dt], PHÚT[@dt], GIÂY[@dt], NGÀY[@dt], TUẦN[@dt], THÁNG[@dt], QUÝ[@dt]
PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này