İki tarih arasındaki gün, ay, yıl, saat, dakika, sn hesa

Katılım
5 Eylül 2004
Mesajlar
571
Excel Vers. ve Dili
Excel 2003 SP1 Ingilizce
Ýki tarih arasındaki gün, ay, yıl, saat, dakika, sn hesa

Merhaba :hey:

Aşağıda hem linki verdim hemde içindekileri (bazen insanın öyle bir günü olurki, linke gidip balkmaya üşenir.. :hiho: ).

http://members.rogers.com/douglas.j.steele/Diff2Dates.html

A More Complete DateDiff Function
The following is a function I helped Graham Seach develop. As it states, it lets you calculate a "precise" difference between two date/time values.
You specify how you want the difference between two date/times to be calculated by providing which of ymdhns (for years, months, days, hours, minutes and seconds) you want calculated.

For example:

?Diff2Dates("y", #06/01/1998#, #06/26/2002#)
4 years
?Diff2Dates("ymd", #06/01/1998#, #06/26/2002#)
4 years 25 days
?Diff2Dates("ymd", #06/01/1998#, #06/26/2002#, True)
4 years 0 months 25 days
?Diff2Dates("d", #06/01/1998#, #06/26/2002#)
1486 days

?Diff2Dates("h", #01/25/2002 01:23:01#, #01/26/2002 20:10:34#)
42 hours
?Diff2Dates("hns", #01/25/2002 01:23:01#, #01/26/2002 20:10:34#)
42 hours 47 minutes 33 seconds
?Diff2Dates("dhns", #01/25/2002 01:23:01#, #01/26/2002 20:10:34#)
1 day 18 hours 47 minutes 33 seconds

?Diff2Dates("ymd",#12/31/1999#,#1/1/2000#)
1 day
?Diff2Dates("ymd",#1/1/2000#,#12/31/1999#)
-1 day
?Diff2Dates("ymd",#1/1/2000#,#1/2/2000#)
1 day
Special thanks to Mike Preston for pointing out an error in how it presented values when Date1 is before Date2.
Kod:
--------------------------------------------------------------------------------

'***************** Code Start **************
Public Function Diff2Dates(Interval As String, Date1 As Date, Date2 As Date, _
Optional ShowZero As Boolean = False) As Variant
'Author:    ) Copyright 2001 Pacific Database Pty Limited
'           Graham R Seach MCP MVP [email]gseach@pacificdb.com.au[/email]
'           Phone: +61 2 9872 9594  Fax: +61 2 9872 9593
'           This code is freeware. Enjoy...
'           (*) Amendments suggested by Douglas J. Steele MVP
'
'Description:   This function calculates the number of years,
'               months, days, hours, minutes and seconds between
'               two dates, as elapsed time.
'
'Inputs:    Interval:   Intervals to be displayed (a string)
'           Date1:      The lower date (see below)
'           Date2:      The higher date (see below)
'           ShowZero:   Boolean to select showing zero elements
'
'Outputs:   On error: Null
'           On no error: Variant containing the number of years,
'               months, days, hours, minutes & seconds between
'               the two dates, depending on the display interval
'               selected.
'           If Date1 is greater than Date2, the result will
'               be a negative value.
'           The function compensates for the lack of any intervals
'               not listed. For example, if Interval lists "m", but
'               not "y", the function adds the value of the year
'               component to the month component.
'           If ShowZero is True, and an output element is zero, it
'               is displayed. However, if ShowZero is False or
'               omitted, no zero-value elements are displayed.
'               For example, with ShowZero = False, Interval = "ym",
'               elements = 0 & 1 respectively, the output string
'               will be "1 month" - not "0 years 1 month".

On Error GoTo Err_Diff2Dates

   Dim booCalcYears As Boolean
   Dim booCalcMonths As Boolean
   Dim booCalcDays As Boolean
   Dim booCalcHours As Boolean
   Dim booCalcMinutes As Boolean
   Dim booCalcSeconds As Boolean
   Dim booSwapped As Boolean
   Dim dtTemp As Date
   Dim intCounter As Integer
   Dim lngDiffYears As Long
   Dim lngDiffMonths As Long
   Dim lngDiffDays As Long
   Dim lngDiffHours As Long
   Dim lngDiffMinutes As Long
   Dim lngDiffSeconds As Long
   Dim varTemp As Variant

   Const INTERVALS As String = "dmyhns"

'Check that Interval contains only valid characters
   Interval = LCase$(Interval)
   For intCounter = 1 To Len(Interval)
      If InStr(1, INTERVALS, Mid$(Interval, intCounter, 1)) = 0 Then
         Exit Function
      End If
   Next intCounter

'Check that valid dates have been entered
   If Not (IsDate(Date1)) Then Exit Function
   If Not (IsDate(Date2)) Then Exit Function

'If necessary, swap the dates, to ensure that
'Date1 is lower than Date2
   If Date1 > Date2 Then
      dtTemp = Date1
      Date1 = Date2
      Date2 = dtTemp
      booSwapped = True
   End If

   Diff2Dates = Null
   varTemp = Null

'What intervals are supplied
   booCalcYears = (InStr(1, Interval, "y") > 0)
   booCalcMonths = (InStr(1, Interval, "m") > 0)
   booCalcDays = (InStr(1, Interval, "d") > 0)
   booCalcHours = (InStr(1, Interval, "h") > 0)
   booCalcMinutes = (InStr(1, Interval, "n") > 0)
   booCalcSeconds = (InStr(1, Interval, "s") > 0)

'Get the cumulative differences
   If booCalcYears Then
      lngDiffYears = Abs(DateDiff("yyyy", Date1, Date2)) - _
              IIf(Format$(Date1, "mmddhhnnss") <= Format$(Date2, "mmddhhnnss"), 0, 1)
      Date1 = DateAdd("yyyy", lngDiffYears, Date1)
   End If

   If booCalcMonths Then
      lngDiffMonths = Abs(DateDiff("m", Date1, Date2)) - _
              IIf(Format$(Date1, "ddhhnnss") <= Format$(Date2, "ddhhnnss"), 0, 1)
      Date1 = DateAdd("m", lngDiffMonths, Date1)
   End If

   If booCalcDays Then
      lngDiffDays = Abs(DateDiff("d", Date1, Date2)) - _
              IIf(Format$(Date1, "hhnnss") <= Format$(Date2, "hhnnss"), 0, 1)
      Date1 = DateAdd("d", lngDiffDays, Date1)
   End If

   If booCalcHours Then
      lngDiffHours = Abs(DateDiff("h", Date1, Date2)) - _
              IIf(Format$(Date1, "nnss") <= Format$(Date2, "nnss"), 0, 1)
      Date1 = DateAdd("h", lngDiffHours, Date1)
   End If

   If booCalcMinutes Then
      lngDiffMinutes = Abs(DateDiff("n", Date1, Date2)) - _
              IIf(Format$(Date1, "ss") <= Format$(Date2, "ss"), 0, 1)
      Date1 = DateAdd("n", lngDiffMinutes, Date1)
   End If

   If booCalcSeconds Then
      lngDiffSeconds = Abs(DateDiff("s", Date1, Date2))
      Date1 = DateAdd("s", lngDiffSeconds, Date1)
   End If

   If booCalcYears And (lngDiffYears > 0 Or ShowZero) Then
      varTemp = lngDiffYears & IIf(lngDiffYears <> 1, " years", " year")
   End If

   If booCalcMonths And (lngDiffMonths > 0 Or ShowZero) Then
      If booCalcMonths Then
         varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
                   lngDiffMonths & IIf(lngDiffMonths <> 1, " months", " month")
      End If
   End If

   If booCalcDays And (lngDiffDays > 0 Or ShowZero) Then
      If booCalcDays Then
         varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
                   lngDiffDays & IIf(lngDiffDays <> 1, " days", " day")
      End If
   End If

   If booCalcHours And (lngDiffHours > 0 Or ShowZero) Then
      If booCalcHours Then
         varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
                   lngDiffHours & IIf(lngDiffHours <> 1, " hours", " hour")
      End If
   End If

   If booCalcMinutes And (lngDiffMinutes > 0 Or ShowZero) Then
      If booCalcMinutes Then
         varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
                   lngDiffMinutes & IIf(lngDiffMinutes <> 1, " minutes", " minute")
      End If
   End If

   If booCalcSeconds And (lngDiffSeconds > 0 Or ShowZero) Then
      If booCalcSeconds Then
         varTemp = varTemp & IIf(IsNull(varTemp), Null, " ") & _
                   lngDiffSeconds & IIf(lngDiffSeconds <> 1, " seconds", " second")
      End If
   End If

   If booSwapped Then
      varTemp = "-" & varTemp
   End If

   Diff2Dates = Trim$(varTemp)

End_Diff2Dates:
   Exit Function

Err_Diff2Dates:
   Resume End_Diff2Dates

End Function
'************** Code End *****************
 
Katılım
3 Kasım 2004
Mesajlar
1
AY-GÜN-YIL

TEÞEKKÜR EDERİİM YARDIMSI OLDUÐUNUZ İÇİN AMA O FORMÜLÜ KULLANDIÐIMDA İÞLEM YAPMIYO BEN DAH ÇOK ÇOK İYİ BİR EXCEL KULLANICISI DEÐİLİM O YÜZDEN TAMOLARAK NE YAPACAÐIMI YAZARSANIZ SEVİNİRİM AYRICA OFFICE BENDE TÜRKÇE BU BİÞEYİ DEÐİÞTİRİR Mİ
 
Katılım
5 Eylül 2004
Mesajlar
571
Excel Vers. ve Dili
Excel 2003 SP1 Ingilizce
Merhaba :hey:
Hoşgeldiniz .Excel diye yanlışlıkla yazdınız değil mi.?Bu bölüm access . :hiho:

Boş bir access açın.Tablonun göründüğü yerde modules var en altta, ona tıklayın ve yeni bir module açılsın.Kod diye yazılanları kopyalayıp, bunun içine yapıştırın ve save, debug edin.

Sonra form a geçin ve yeni bir form oluşturun, Tarih1, Tarih2, yil, ay, gun diye 5 tane unbound textbox oluşturun.

Ã?rneğin

gün için control source’una (propertiesin atında)
=Diff2Dates("d";[Tarih1];[Tarih2])
ay için
=Diff2Dates("m";[Tarih1];[Tarih2])
yıl için
=Diff2Dates("y";[Tarih1];[Tarih2])

veya alıntı içindeki örneklerden birşeyler yazın.

Bu anlattıklarımla yapamazsanız da haber verin.

İyi Çalışmalar
 
X

xxrt

Misafir
İlk defa accessi deniyeceğim ama Form1 içinde Textboxları kurdum ama date kodlarını nereye yazacağımı bulamadım..İlla öğrencem bu acceessi..AYrıca Ofisim Tr.
 
Katılım
5 Eylül 2004
Mesajlar
571
Excel Vers. ve Dili
Excel 2003 SP1 Ingilizce
Merhaba xxrt

Bende senin denemene çok memnun oldum.Ã?ğren şu accessi artık, yeter excelden çektiklerin.. :hiho: :hiho: :hiho:

Metin kutusu:metin4 de tümü'nün şeklini buraya yukarıya yerleştirmişsin ya.İşte orada 2. sıradaki olacak.Türkçesi denetim kaynağı imiş, ingilizcesi:Control source.
 
Katılım
5 Eylül 2004
Mesajlar
571
Excel Vers. ve Dili
Excel 2003 SP1 Ingilizce
Biz buradayız efem bekleriz. :hihoho: :hihoho: :hihoho:
 
Katılım
5 Eylül 2004
Mesajlar
571
Excel Vers. ve Dili
Excel 2003 SP1 Ingilizce
access 2000 format

Bir örnek ekliyorum.

datediff.zip
 
Katılım
8 Kasım 2004
Mesajlar
207
jale hanım çok çok çok teşekkür ediyorum.Ã?zellikle ben çok işime yaradı .Forumda sizi görmekten bilgilerinizi bizimle paylaşmanızdan çok mutlu oluyorum.Kolay gelsin.
 
Katılım
5 Eylül 2004
Mesajlar
571
Excel Vers. ve Dili
Excel 2003 SP1 Ingilizce
Teşekkürler Ahmet Bey,

Sorularınızı aslında foruma sorarsanız ,diğer arkadaşlarda size cevap yazabilirler. :lol:

Belki bu arada Sayın xxrt de access'e geri dönüş yapar. :hiho: :hiho: :hiho:
 
X

xxrt

Misafir
Belki bu arada Sayın xxrt de access'e geri dönüş yapar
Sayın Hocam,Ã?nce o dosyada benim işime yaradı.Zaten şu an Access ile ilgili basit çalışmalarım var,ama çok sık uğraşamıyorum.Daha Bu forumdayız inşallah diyorum.
 
Katılım
8 Kasım 2004
Mesajlar
207
burdaki ingilice yazan yerleri türkçe yapma durumumuz yokmu yani 1 year 5 month 4 day bunu 1 yıl 5 ay 4 gün gibi yazamazmı modulun neresinde değişiklik yapmamız lazım
 
Katılım
8 Kasım 2004
Mesajlar
207
jale hanım modulden hepsini türkçeye çevirdim yil yazdım onu türkçeye çeviremedim
 
Katılım
8 Kasım 2004
Mesajlar
207
yalnız bir sorunum daha var ...tarih1 ben giriş maskesine tabloda =date$() girdim yani bugünün tarihini girdim..ben sürekli tarih 2 den tarih1 çıkartılmasını ve aradaki gün 10 gün kaldığında bana söylemesini istiyorum ..burada ben örneği uyguladım..... o günün tarihine göre işlem yapıyor...yani yarın olduğunda 1 gün eksilip şu kadar gün kaldı.demiyor...dünkü değerleri söylüyor...bir yerde hatamı yaptım yoksa modülmü o şekilde yazılmış...sağolun cevaplar için şimdiden
 
Katılım
20 Mayıs 2005
Mesajlar
14
slm hocam aylık rapor hazırlamam gerekiyor sorgu da ölçüt kısmınaotamatik yapması için ne yapmama gerekiyor
 
Katılım
31 Mayıs 2010
Mesajlar
4
Excel Vers. ve Dili
2007 türkçe
A1'e başlangıç tarihi,B1'e ise Bitiş tarihini yazdığımızı varsayarsak,formül aşağıdaki gibi olur,

=EĞER(A1<=B1;ETARİHLİ(A1;B1;"y")&" Yıl,"&" "&ETARİHLİ(A1;B1;"ym")&" Ay,"&" "&ETARİHLİ(A1;B1;"md")&" Gün";"-"&ETARİHLİ(B1;A1;"y")&" Yıl,"&" "&ETARİHLİ(B1;A1;"ym")&" Ay,"&" "&ETARİHLİ(B1;A1;"md")&" Gün")
 
Katılım
31 Mayıs 2010
Mesajlar
4
Excel Vers. ve Dili
2007 türkçe
Yukarıdaki formül excel içindir ve iki tarih arasındaki tarihi gün, ay, yıl şeklinde çevirir.
 
Üst