ผู้เขียน หัวข้อ: รบกวนถามเรื่องคำสั่งที่ใช้ในการลบวันที่ และเวลา  (อ่าน 12917 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ jassada

  • Sr. Member
  • ****
  • กระทู้: 379
  • Respect: 0
    • ดูรายละเอียด
    • โรงพยาบาลปากพนัง
จะทำรายงานหาระยะรอคอยของผู้ป่วยห้อง Lab  แต่มีปัญหาตรงที่ เวลาที่รับ  order  กับเวลาที่รายงานผล
เช่น  รับ order      วันที่    20/07/2550   เวลา  10.00  น. 
        รายงานผล    วันที่   21/07/2550   เวลา   09.00  น.   
  เวลารายงานผล น้อยกว่าเวลารับ order  จึงรบกวนถามการเขียนคำสังลบวันที่และเวลา    ถ้ารายงานผลวันเดียวกับ วันรับ order  จะไม่มีปัญหา เพราะ เวลารายงานผลต้องมากกว่า เวลารับ order อยู่แล้ว
Pakphanang Hospital
Server Master : HP  Xeon 2.13 GHz Ram 32 Gb  Centos 6.2 64 bit  (Mysql 5.5.31-30.3  64 bit)
Server Slave : Acer  Xeon 3.0x2 GHz Ram 6 Gb  Centos 4.8 64 bit  (Mysql 5.1.42 percona xtradb 64 bit)

DB : 3.56.4.22
Cliant :  Hosxp 3.56.1.15
Activation @ 02-01-56

ออฟไลน์ naj

  • Hero Member
  • *****
  • กระทู้: 2,449
  • Respect: +8
    • ดูรายละเอียด
    • http://www.luangphopern-hospital.com
0
ขอค้นดูก่อนนะครับ เนื่องจากจำคำสั่งไม่ได้  แล้วจะมาตอบให้ครับ
Yindee And Tan

ออฟไลน์ nuttavut

  • Hero Member
  • *****
  • กระทู้: 2,634
  • Boom-Beam
  • Respect: +15
    • ดูรายละเอียด
    • โรงพยาบาลวิเชียรบุรี
0
ขอ function บวกลบวันที่ครับ  เช่น วันที่+1 หรือวันที่-หนึ่ง ไม่ทราบว่าเขียนอย่างไรใน report design
..Wichianburi Hospital  Phetchabun ..
Mr.Nuttavut   System Admin,Programer
Master:: HP DL380 G7 RAM 24GB Raid5 CentOS5.2  Percona 5.1.45
Slave::HP ProLiant ML150G3 Xeon Raid1  CentOS5.2   ,Percona 5.1.45
HOSxP 3.55.7.14, LIS (iLab),PACS
Tel. 0-5692-8169 ต่อ 180  | รพ. ขนาด 150+ เตียง |17 สอ. HOSxP_PCU |BMS Datacenter 18 node |
WWW : http://wichianhos.thaieasydns.com
|..ดูแลห่วงใย ใส่ใจบริการ รักษาได้มาตรฐาน พัฒนางานสู่ความเป็นเลิศ ..|   PDS Project  |  การนำเข้า Script คลิก

ออฟไลน์ anukul

  • Hero Member
  • *****
  • กระทู้: 1,363
  • Respect: +1
    • ดูรายละเอียด
0
DATE_ADD(date,INTERVAL expr unit), DATE_SUB(date,INTERVAL expr unit)

These functions perform date arithmetic. date is a DATETIME or DATE value specifying the starting date. expr is an expression specifying the interval value to be added or subtracted from the starting date. expr is a string; it may start with a ‘-’ for negative intervals. unit is a keyword indicating the units in which the expression should be interpreted.

The INTERVAL keyword and the unit specifier are not case sensitive.


The values QUARTER and WEEK are available beginning with MySQL 5.0.0.

MySQL allows any punctuation delimiter in the expr format. Those shown in the table are the suggested delimiters. If the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts (that is, no time parts), the result is a DATE value. Otherwise, the result is a DATETIME value.

Date arithmetic also can be performed using INTERVAL together with the + or - operator:

date + INTERVAL expr unit
date - INTERVAL expr unit
INTERVAL expr unit is allowed on either side of the + operator if the expression on the other side is a date or datetime value. For the - operator, INTERVAL expr unit is allowed only on the right side, because it makes no sense to subtract a date or datetime value from an interval.

mysql> SELECT '1997-12-31 23:59:59' + INTERVAL 1 SECOND;
        -> '1998-01-01 00:00:00'
mysql> SELECT INTERVAL 1 DAY + '1997-12-31';
        -> '1998-01-01'
mysql> SELECT '1998-01-01' - INTERVAL 1 SECOND;
        -> '1997-12-31 23:59:59'
mysql> SELECT DATE_ADD('1997-12-31 23:59:59',
    ->                 INTERVAL 1 SECOND);
        -> '1998-01-01 00:00:00'
mysql> SELECT DATE_ADD('1997-12-31 23:59:59',
    ->                 INTERVAL 1 DAY);
        -> '1998-01-01 23:59:59'
mysql> SELECT DATE_ADD('1997-12-31 23:59:59',
    ->                 INTERVAL '1:1' MINUTE_SECOND);
        -> '1998-01-01 00:01:00'
mysql> SELECT DATE_SUB('1998-01-01 00:00:00',
    ->                 INTERVAL '1 1:1:1' DAY_SECOND);
        -> '1997-12-30 22:58:59'
mysql> SELECT DATE_ADD('1998-01-01 00:00:00',
    ->                 INTERVAL '-1 10' DAY_HOUR);
        -> '1997-12-30 14:00:00'
mysql> SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
        -> '1997-12-02'
mysql> SELECT DATE_ADD('1992-12-31 23:59:59.000002',
    ->            INTERVAL '1.999999' SECOND_MICROSECOND);
        -> '1993-01-01 00:00:01.000001'
If you specify an interval value that is too short (does not include all the interval parts that would be expected from the unit keyword), MySQL assumes that you have left out the leftmost parts of the interval value. For example, if you specify a unit of DAY_SECOND, the value of expr is expected to have days, hours, minutes, and seconds parts. If you specify a value like '1:10', MySQL assumes that the days and hours parts are missing and the value represents minutes and seconds. In other words, '1:10' DAY_SECOND is interpreted in such a way that it is equivalent to '1:10' MINUTE_SECOND. This is analogous to the way that MySQL interprets TIME values as representing elapsed time rather than as a time of day.

If you add to or subtract from a date value something that contains a time part, the result is automatically converted to a datetime value:

mysql> SELECT DATE_ADD('1999-01-01', INTERVAL 1 DAY);
        -> '1999-01-02'
mysql> SELECT DATE_ADD('1999-01-01', INTERVAL 1 HOUR);
        -> '1999-01-01 01:00:00'
If you add MONTH, YEAR_MONTH, or YEAR and the resulting date has a day that is larger than the maximum day for the new month, the day is adjusted to the maximum days in the new month:

mysql> SELECT DATE_ADD('1998-01-30', INTERVAL 1 MONTH);
        -> '1998-02-28'
Date arithmetic operations require complete dates and do not work with incomplete dates such as '2006-07-00' or badly malformed dates:

mysql> SELECT DATE_ADD('2006-07-00', INTERVAL 1 DAY);
        -> NULL
mysql> SELECT '2005-03-32' + INTERVAL 1 MONTH;
        -> NULL
รพ.มะการักษ์ 260 เตียง
เริ่มระบบ 1 ธค 48 (ทีม MN)
Database structure :HOSxP 3.55.9.21b
Client : 3.55.6.8-3.55.9.21b
Server : Double QuadCore XEON 3.2 G. ECC 18 G. SAS 146 G x4(Raid 5) -- CentOS 5.3 (64 bit) , MySQL 5.1.30 percana
Client : Win2000 ~ 200 clients
Module :
OPD -Register,Screening,Doctor,Dispense,Billing,Dentist,PMMR
IPD - Admit center,Ward,Nutrition,Dispense,LR,OR
LAB , X-ray
การเชื่อมต่อ : LIS             --> RAX
                    X-ray PACS --> Infinitt (ThaiGL)

ออฟไลน์ manoi

  • Hero Member
  • *****
  • กระทู้: 8,669
  • Respect: +170
    • ดูรายละเอียด
    • HOSxP Community Center
0
ถ้้าเป็น pascal ก็บวกกับเลขจำนวนเต็มได้เลยครับ อย่างเช่น

var d1 : TDateTime;
begin
  d1 := StrToDate('01/01/2007');
 
  d1:= d1 + 1;  // = 02/01/2007

end;
HOSxP Project Manager / Cheif Developer / BMS MD