الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف يمكن طرح التاريخ بال sql?

مغلق
بدأه shario في 6 مايو 2001 · 1 رد · 5,392 مشاهدة · في أرشيف قسم SQL Server
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله

الاستاذ العزيز خضر كيف حالك أود أن استفسار منك عن كيفية كتابة كود sql ليقوم بطرح التاريخ (النظام) اي تاريخ اليوم من تاريخ أخر ويحسب الفرق بينهما...

============ملاحظة:

التاريخ dd/mm/yyyy

=============================

بمعنى أخر أود عمل استعلام عن الكتب الحديثة فى برنامج مكتبة بحيث مثلا لو أردنا الاستعلام عن الكتب المسجلة خلال 15 يوم السابقين كيف يمكن عمل ذلك بواسطة الsql

بحيث سوف تكون هناك مشكلة وهي فى حالة لو كان اليوم أو الشهر فى تاريخ النظام أقل من التاريخ المسجل

======================*ملاحظة:

وهل يمكن استخدام الجمل الشرطية if مثلا... فى الsql كما فى c وال visual basic واذا كانت الاجابة بنعم ارجو توضيح كيفية كتابة الجملة وأرجو أن تتركنى :) أقوم بمحاولة حل هذه المشكلة وسوف أعرضها عليك....:)

=========================================

وشكرا لك جزيلا وجزاك الله خيرا........

#2

بالنسبة ل Microsoft SQL Server فهو يدعم كل مواصفات SQL 92 القياسية و اضافة الى ذلك Transact SQL الخاصة بمايكروسوفت

و SQL 92 مدعمة ب Transact SQL هي لغة برمجة متكاملة بها اجرائات و اوامر و متغيرات و اوامر تكرار و اوامر شرط مثل ال if ايضا ، و الكثير الكثير من الاوامر ، يعني ببساطة لغة برمجة متكاملة

و الجيد بها انها تعمل على طرف الجهاز المركزي او على طرف الجهاز الذي يحتوي على ال SQL Server و هي اسرع طريقة لمعالجة البيانات بداخل قاعدة البيانات على الاطلاق اسرع من اية لغة برمجة اخرى لانها تنفذ بداخل خادم قواعد البيانات و هي قادرة على احتساب عدة ملايين من السجلات في دقائق بسيطة (هذا حسب الاختبارات على الاجهزة المركزية عندنا)

على العموم امر معالجة التواريخ و طرحهم من بعضهم هو

DATEDIFF

Returns the number of date and time

boundaries crossed between two specified dates.

Syntax

DATEDIFF ( datepart

, startdate , enddate )

Arguments

datepart

Is the parameter that

specifies on which part of the date to calculate the difference. The table lists

dateparts and abbreviations recognized by Microsoft® SQL Server™.

Datepart

Abbreviations

Year

yy, yyyy

quarter

qq, q

Month

mm, m

dayofyear

dy, y

Day

dd, d

Week

wk, ww

Hour

hh

minute

mi, n

second

ss, s

millisecond

ms

 

startdate

Is the beginning date

for the calculation. startdate is an expression that returns a

datetime or smalldatetime value, or a character string in a date

format.

Because

smalldatetime is accurate only to the minute, when a smalldatetime

value is used, seconds and milliseconds are always 0.

If you specify only

the last two digits of the year, values less than or equal to the last two

digits of the value of the two digit year cutoff configuration option are

in the same century as the cutoff year. Values greater than the last two digits

of the value of this option are in the century that precedes the cutoff year.

For example, if the two digit year cutoff is 2049 (default), 49 is

interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use

four-digit years.

For more information

about specifying time values, see Time

Formats. For more information about specifying dates, see

datetime and smalldatetime.

enddate

Is the ending date for

the calculation. enddate is an expression that returns a datetime

or smalldatetime value, or a character string in a date format.

Return Types

integer

Remarks

startdate is subtracted from

enddate. If startdate is later than enddate, a negative

value is returned.

DATEDIFF produces an error if the

result is out of range for integer values. For milliseconds, the maximum number

is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum

number is 68 years.

The method of counting crossed

boundaries such as minutes, seconds, and milliseconds makes the result given by

DATEDIFF consistent across all data types. The result is a signed integer value

equal to the number of datepart boundaries crossed between the first and

second date. For example, the number of weeks between Sunday, January 4, and

Sunday, January 11, is 1.

Examples

This example determines the

difference in days between the current date and the publication date for titles

in the pubs database.

GO

SELECT DATEDIFF(day, pubdate, getdate()) AS no_of_days

FROM titles

GO

 

See Also

 

CAST and CONVERT

Data Types

Date and Time Functions

هذا الموضوع مغلق.

مواضيع مشابهة