Senin, 17 Januari 2011

get last day of month

    Private Sub Command1_Click()
    Dim mDate As Date
    mDate = CDate("01" & Mid(Text1.Text, 3))
    Text2.Text = Format(DateAdd("d", -1, DateAdd("M", 1,mDate)), "dd/MM/yyyy")
    End Sub

  Function CekTglAkhirBln(Tgl As Date) As Date
      CekTglAkhirBln = DateSerial(Year(Tgl), Month(Tgl) + 1, Day(Tgl)) -
Day(Tgl)
  End Function

 


Private Function GetLastDayInMonth(ByVal dDate As Date) As Date
dDate = DateAdd(DateInterval.Month, 1, dDate)
dDate = Convert.ToDateTime(Month(dDate).ToString() & "/" & "1/" & Year(dDate).ToString())
dDate = DateAdd(DateInterval.Day, -1, dDate)
Return dDate
End Function


function GetLastDay(aDate)
    dim intMonth
    dim dteFirstDayNextMonth

    dtefirstdaynextmonth = dateserial(year(adate),month(adate) + 1, 1)
    GetLastDay = Day(DateAdd ("d", -1, dteFirstDayNextMonth))
end function


dim date1 as date
dim date2 as date
dim days as long
date1=#1/1/2007# ' note -- use date literals, not string literals
date2=#1/1/2006#
days=datediff("d",date2,date1) ' the earlier date usually comes first


SQL DATEDIFF Function

Returns the number of date and time boundaries crossed between two dates

SQL DATEDIFF Syntax
DATEDIFF ( DatePart , StartDate , EndDate )

DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate ='2007-06-05'
SET @EndDate ='2007-08-05'

SELECT DATEDIFF(Year, @StartDate, @EndDate) AS NewDate
Return Value = 0 Year


SELECT DATEDIFF(quarter, @StartDate, @EndDate) AS NewDate
Return Value = 1 quarter


SELECT DATEDIFF(Month, @StartDate, @EndDate) AS NewDate
Return Value = 2 Month


SELECT DATEDIFF(dayofyear,@StartDate, @EndDate) AS NewDate
Return Value = 61 day


SELECT DATEDIFF(Day, @StartDate, @EndDate) AS NewDate
Return Value = 61 Day


SELECT DATEDIFF(Week, @StartDate, @EndDate) AS NewDate
Return Value = 9 Week


SELECT DATEDIFF(Hour, @StartDate, @EndDate) AS NewDate
Return Value = 1464 Hour


SELECT DATEDIFF(minute, @StartDate, @EndDate) AS NewDate
Return Value = 87840 minute


SELECT DATEDIFF(second, @StartDate, @EndDate) AS NewDate
Return Value = 5270400 second


DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate ='2007-06-05'
SET @EndDate ='2007-06-06'

SELECT DATEDIFF(millisecond, @StartDate, @EndDate) AS NewDate
Return Value = 86400000 millisecond

Tidak ada komentar:

Posting Komentar