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

سؤال في التعامل مع التاريخ في ASP

مغلق
بدأه abu saad في 22 سبتمبر 2004 · 9 رد · 1,272 مشاهدة · في منتدى تصميم صفحات الويب
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

لدي تاريخ مثلا 01/01/1425 واريد التعامل معه بحيث استطيع المقارنة بينهما او اجد الفرق بينهما

مع العلم ان الغه المستخدمة هي asp

#2

هل تريد وضع عدة تواريخ و تحديد الفرق بينهما؟ أم تريد أساليب اخرى لعرض التاريخ غير الذي ذكرته، ربما السؤال يحتاج إلى توضيح أكثر.

علماً أني لم أتعامل بالتاريخ الهجري من قبل...

Mohamad Al-Karbi

www.mkarbi.me

#3

الموضوع هو في وضع التاريخ بهذه الطريقة ( 01/01/1425) اريد ان اتعامل معه

مثلا : حساب عمر شخص تاريخ ميلاده 10/02/1400

اتمنا ان تكون الفكرة وضحة .....

#4

والله يا أخي لا أعلم. و لولا امتحاناتي الحالية لبحثت لك عن الطريقة و لكني لا أجد الوقت للبحث الآن. إذ لم أتعامل بهذا الموضوع من قبل... و كنت قد قرأت عنه سابقاً و لكني نسيت حيث يتم تقسيم وهمي لخانات التاريخ في functions لتسهيل الاحتساب...

على كل حال احببت أن أخبرك عسى أن يكون هناك من يستطيع الإجابة السريعة عن سؤالك أو أجد المعلومات المطلوبة قبل ذلك

Mohamad Al-Karbi

www.mkarbi.me

#5

أولا ، انظر:

/index.php?showtopic=47170

ثانيا:

جربت هذا الكود(بالVB6):

Calendar = vbCalHijri
    Dim d1  As Date
    d1 = Now
    Dim d2 As Date
    d2 = CDate(#1/8/1425#)
    Calendar = vbCalGreg
    MsgBox (DateDiff("d", d1, d2))

ولكن لديه مشكلة في هذا السطر

   d2 = CDate(#1/8/1425#)

، حيث لا ينجح في التعرف على التاريخ بهذه الصيغة، فيعطي عدد أيام بعشرات الآلاف :huh:

ما أقصده هو تحويل التاريخين الهجريين لمقابلهما الميلاديين ، ومن ثم إيجاد الفرق ، مع خطأ حوالي يوم أو يومين.

من لديه افكار أخرى فليفيدنا رجاء.

فكر بطريقة أخرى

#6

كنت قد وضعت هنا ملف dll يقوم بالتحويل بين التاريخ الميلادى و الهجرى يمكن استخدامه بداخل ال asp

/index.ph...pic=37444&st=15

و لاستخدام الملف داخل ال ASP ستقوم اولاً بتسجيل الملف فى الريجيسترى باستخدام

regsvr32 mydll.dll

ثم بداخل كود ال asp

dim datedll
set datedll =Server.CreateObject("ProjectName.ClassModuleName")
hijridate='use the suitable function

اول سطر من الكود ستقوم فيه بتعريف كائن جديد من ملف ال dll و فى السطر الثانى ستقوم بعمل ال Instantiation ثم ستقوم باستخدام دوال ملف ال dll ببساطه شديده

ستحصل على المقابل الميلادى للتاريخ الهجرى ثم ستقوم كما اوضح وليد باعلى بإيجاد الفرق بين التاريخين باستخدام datediff

تم تعديل هذه المشاركة بواسطة طارق إبراهيم في 28 سبتمبر 2004 في 10:50

Technical Lead Developer

My LinkedIn Profile

اللهم قنى شر الجهل و الجهلاء

( اقْتَرَبَ لِلنَّاسِ حِسَابُهُمْ وَهُمْ فِي غَفْلَةٍ مَّعْرِضُونَ ) {الأنبياء:1}

#7

اشكر الجميع على ردودهم

ومع البحث وجدة طريقة واحببت افيدكم بها

اولا هذه الطرريقة ممتازة للتعامل مع التاريخ من جميع الجهات وهي

دالت MID بحيث يتم تقسيم التاريخ الى ثلاث قطع

السنة ------ الشهر ------ اليوم

1425 ------ 02 ------ 27

بحيث يوضع كل مقطع في متغير وبذلك يمكن التحكم به

وترتيب ذلك حسب المطلوب اما البدء بالسنة او باليوم

اعتقد ان الطريقة واضحة وان اردتم التفصيل اكثر فهذا يسعدني

تم تعديل هذه المشاركة بواسطة abu saad في 29 سبتمبر 2004 في 11:41

#8

السلام عليكم

اظن ان هناك ما هو افضل من الطريقة التي قمت بعرضها

قد يفيدك الدرس ادناه

Format Dates and Times

To format dates and times you simply need one function: FormatDateTime(). This function is detailed and explained below:

FormatDateTime(Date[, Format])
- returns a date formatted as you specify
- the format parameter can have one of the following values:
0 - vbGeneralDate - Displays date as short date (if included), and time as long time. 
1 - vbLongDate - Displays date as long date format 
2 - vbShortDate - Displays date as short date 
3 - vbLongTime - Displays time as long time 
4 - vbShortTime - Displays time in 24 format (hh:mm)

Example:

var1 = Now()
Response.Write("var1 before formatting : " & var1 & "<br>")
Response.Write("var1 format 0 = " & FormatDateTime(var1,0) & "<br>")
Response.Write("var1 format 1 = " & FormatDateTime(var1,1) & "<br>")
Response.Write("var1 format 2 = " & FormatDateTime(var1,2) & "<br>")
Response.Write("var1 format 3 = " & FormatDateTime(var1,3) & "<br>")
Response.Write("var1 format 4 = " & FormatDateTime(var1,4) & "<br>")

Result:

var1 before formatting : 9/1/99 12:34:50 PM
var1 format 0 = 9/1/99 12:34:50 PM
var1 format 1 = Wednesday, September 01, 1999
var1 format 2 = 9/1/99
var1 format 3 = 12:34:50 PM
var1 format 4 = 12:34


Date Manipulation Part 1 : Extracting parts of the date out with DatePart()

DatePart(PartOfDate, Date[, FirstDayOfWeek, FirstDayOfYear])
- returns the request part of the date
- optional parameters are setting the first day of the week (defaults to Sunday), and setting the first week of the year (defaults to Jan 1).

FirstDayOfWeek optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Sunday (the default value if this parameter is not supplied)
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday

FirstDayOfYear optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Start with the week that has Jan 1 in it (the default value if this parameter is not supplied)
2 - Start with the first week that contains at least four days in the new year.
3 - Start with the first week that is a full week in the new year.

- I recommend just leaving the two optional parameters out unless they specifically apply to what you are currently trying to do.

PartOfDate parameter can have the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second

An example of what each of those values will output is:

var1 = Now()
Response.Write("var1 = " & var1 & "<br>")
Response.Write("var1 part yyyy = " & DatePart("yyyy", var1) & "<br>")
Response.Write("var1 part m = " & DatePart("m", var1) & "<br>")
Response.Write("var1 part q = " & DatePart("q", var1) & "<br>")
Response.Write("var1 part y = " & DatePart("y", var1) & "<br>")
Response.Write("var1 part d = " & DatePart("d", var1) & "<br>")
Response.Write("var1 part w = " & DatePart("w", var1) & "<br>")
Response.Write("var1 part ww = " & DatePart("ww", var1) & "<br>")
Response.Write("var1 part h = " & DatePart("h", var1) & "<br>")
Response.Write("var1 part n = " & DatePart("n", var1) & "<br>")
Response.Write("var1 part s = " & DatePart("s", var1) & "<br>")

Results:
var1 = 9/1/99 1:18:15 PM
var1 part yyyy = 1999
var1 part m = 9
var1 part q = 3
var1 part y = 244
var1 part d = 1
var1 part w = 4
var1 part ww = 36
var1 part h = 13
var1 part n = 18
var1 part s = 15

Date Manipulation Part 2 : Adding & Subtracting Dates & Times

VBScript provides developers with a wonderful function called DateAdd(). With this function you can add or subtract from a date or time.

DateAdd(PartOfDate, AmountToChange, Date)
- returns a date that has been changed the specified amount
- AmountToChange is the number to which you want the date to change (1, -4, 10, etc).
- Date is a valid date
- PartOfDate parameter can have the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second

An example of what each of those values will output is:

var1 = Now()
Response.Write("var1 = " & var1 & "<br>")
Response.Write("var1 plus 10 days = " & DateAdd("d", 10, var1) & "<br>")
Response.Write("var1 minus 10 days = " & DateAdd("d", -10, var1) & "<br>")
Response.Write("var1 plus 3 months = " & DateAdd("m", 3, var1) & "<br>")
Response.Write("var1 minus 3 months = " & DateAdd("m", -3, var1) & "<br>")
Response.Write("var1 plus 2 hours = " & DateAdd("h", 2, var1) & "<br>")
Response.Write("var1 minus 2 hours = " & DateAdd("h", -2, var1) & "<br>")

Results:
var1 = 9/1/99 1:41:04 PM
var1 plus 10 days = 9/11/99 1:41:04 PM
var1 minus 10 days = 8/22/99 1:41:04 PM
var1 plus 3 months = 12/1/99 1:41:04 PM
var1 minus 3 months = 6/1/99 1:41:04 PM
var1 plus 2 hours = 9/1/99 3:41:04 PM
var1 minus 2 hours = 9/1/99 11:41:04 AM

Date Manipulation Part 3 : Find the amount of time between dates with DateDiff()

Find out how much time occurs between two dates is easy with DateDiff(). This function is useful if you need to find the amount of time between one date and another, or if you need to find out how much time is left until the end of the year.

DateDiff(PartOfDate, Date1, Date2[, FirstDayOfWeek, FirstDayOfYear])
- returns the amount of time in between the two dates in the form of PartOfDate, therefore if you set PartOfDate equal to year, the function will tell you how many years are in between Date1 and Date2 even if you are comparing Dec 31 and Jan 1. If you set PartOfDate equal to day then the function will return to you the number of days between Date1 and Date2.
- if Date1 occurs after Date2 the function will return to you a negative number.
- optional parameters are setting the first day of the week (defaults to Sunday), and setting the first week of the year (defaults to Jan 1).

FirstDayOfWeek optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Sunday (the default value if this parameter is not supplied)
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday

FirstDayOfYear optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Start with the week that has Jan 1 in it (the default value if this parameter is not supplied)
2 - Start with the first week that contains at least four days in the new year.
3 - Start with the first week that is a full week in the new year.

- I recommend just leaving the two optional parameters out unless they specifically apply to what you are currently trying to do.

PartOfDate parameter can have the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second

Example of use:

var1 = "04/04/1999"<br> var2 = "01/11/2000"<br>

Response.Write("var1 = " & var1 & "<br>")
Response.Write("var2 = " & var2 & "<br>")
Response.Write("var1 to var2 is " & DateDiff("d", var1, var2) & " days <br>")
Response.Write("var1 to var2 is " & DateDiff("m", var1, var2) & " months <br>")
Response.Write("var1 to var2 is " & DateDiff("yyyy", var1, var2) & " year(s) <br>")

Results:
var1 = 04/04/1999
var2 = 01/11/2000
var1 to var2 is 282 days
var1 to var2 is 9 months
var1 to var2 is 1 year(s)

Date Manipulation Part 4 : Getting the day, month, year, weekday, and weekday name

There are five functions that you can call, pass a valid date, and they will return to you the requested part of the date. Below I will detail each of them and show an example of their use:

Day(ValidDate)
- returns the day of the ValidDate, a number between 1 and 31

Month(ValidDate)
- returns the month of the ValidDate, a number between 1 and 12

Year(ValidDate)
- returns the year of the ValidDate, a number like 1997

Weekday(ValidDate[, FirstDayOfWeek])
- returns the weekday of the ValidDate, a number 1 - 7
- what the function returns depends on what day is the first day of the week, you can set this, or use the default - Sunday
- to set the FirstDayOfWeek parameter use 1-7, where 1 is Sunday

WeekDayName(DayOfWeek, Abbreviate, FirstDayOfWeek)
- returns the name of the day of the week that you specify.
- DayOfWeek is a number representing the day of the week you want the name for (1-7)
- Abbreviate is a boolean value to tell the function whether or not you want the name that comes back to be abbreviated or not (true or false)
- to set the FirstDayOfWeek parameter use 1-7, where 1 is Sunday

An example of the above functions in use is:

var1 = "04/04/1999"<br>
Response.Write("var1 = " & var1 & "<br>")
Response.Write("For var1 the day is " & Day(var1) & "<br>")
Response.Write("For var1 the month is " & Month(var1) & "<br>")
Response.Write("For var1 the year is " & Year(var1) & "<br>")
Response.Write("For var1 the weekday is " & WeekDay(var1, 1) & "<br>")
Response.Write("For var1 the weekdayname is " & WeekDayName(WeekDay(var1), false, 1) & "<br>")

Results:
var1 = 04/04/1999
For var1 the day is 4
For var1 the month is 4
For var1 the year is 1999
For var1 the weekday is 1
For var1 the weekdayname is Sunday
logosite.gif
#9

ردود جميلة و لكن بحد علمي فإن رد الأخ walcom هو المطلوب ..

طبعا هناك طريقتين .. إما استخدام DateDiff أو DateAdd و هذا مثال :

<%
  currentDate=date()

  Response.write "Current Date : " & currentDate & "<BR>"  &_
                            "Difference in months :" & DateDiff("m",currentDate,"13/1/1980") & "<BR>" &_
                            "Difference in days :" & DateDiff("d",currentDate,"13/1/1980") & "<BR>" &_
                            "Difference in hours :" & DateDiff("h",currentDate,"13/1/1980") 
  
%>

و يمكنك الإستزادة من هنا

http://www.w3schools.com/vbscript/func_datediff.asp

أما بالنسبة للدالة الثانية DateAdd يمكنك متابعتها هنا

http://www.asp-help.com/getstarted/ms/vbscript/62.asp

أو من هنا

http://www.w3schools.com/vbscript/func_dateadd.asp

بالتوفيق

تم تعديل هذه المشاركة بواسطة محمد خليل أبو صلاح في 29 سبتمبر 2004 في 22:35

You can fly while you can touch the sky

#10

معليش يا اخوان .. هل الطريقة تقبل مع التاريخ الهجري بالتمام ولا لا ؟

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

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