|
#1
| ||||
| ||||
| C++ C# ve VB.Net ile iki tarih arasındaki fark C++ C# ve VB.Net ile iki tarih arasındaki farkBildiğiniz gibi visaul basic 6 ile bu işlemleri yapmak çok kolaydı daydiff(format,tarih1,tarih2) function unu kullanarak bu işlemler gerçekleştiriliyordu, bunun yerini net te DateTime ve TimeSpan function ları kullanarak alıyoruz... size 3 dilde nasıl alınacağını örneklere göstereceğim. C# ile tarih farkı bulma public int ikitarihfarki (DateTime tr1,DateTime tr2) { TimeSpan Sonuc; Sonuc=(tr2-tr1); return (Sonuc.Days); } //formunuza bir buton ekleyip arkasına şu kodu yazın private void buton1_click(object sender,System.EventArgs e) { MessageBox.Show(ikitarihfarki(new DateTime(2004,2,10),new DateTime(2004,10,10).ToString()); } '------------------------------------------------------------ VB.NET ile tarih farkı bulma public function ikitarihfarki (byval tr1 as DateTime,byval tr2 as DateTime) as integer dim Sonuc as TimeSpan Sonuc=(tr2-tr1) return (Sonuc.Days) end function '-------------------------------------------------------------- 'formunuza bir buton ekleyip arkasına şu kodu yazın private sub buton1_click(byval sender as System.object,byval e as System.EventArgs) MessageBox.Show(ikitarihfarki(new DateTime(2004,2,10),new DateTime(2004,10,10).ToString()) end sub c++ ile tarih farkı bulma // diffdate.h #ifndef DIFFDATE_H #define DIFFDATE_H extern time_t timeFromString( char *date ); extern int DayDiff( char *date1, char *date2 ); #endif // diffdate.c #include <stdio.h> #include <string.h> #include <time.h> time_t timeFromString(char *date) { time_t theTime = 0; int day, month, year; if (date && (3 == sscanf(date, "%d/%d/%d", &month, &day, &year))) { struct tm theTm; memset(&theTm, 0, sizeof(theTm)); theTm.tm_mon = month - 1; theTm.tm_mday = day; theTm.tm_year = year - 1900; theTime = mktime(&theTm); } return theTime; }// end function timeFromString int DayDiff(char *date1, char *date2) { time_t time1, time2; int daydiff; if ((time1 = timeFromString(date1)) && (time2 = timeFromString(date2))) { daydiff = (time2 - time1) / (60*60*24); return (daydiff); } return -1; }// end Function DayDiff |