jjcolo
asked on
Access Date Function that is the equivalent of to_char(Date,'w') in Oracle
I'm trying to use the DateDiff function in Oracle, but it doesn't work the same as Oracles function. For instance, I want March 1, 2003 - March 7, 2003 to show up as "1" when getting the 1st week of this month. Currently March 1, 2003 is "1" and March 2, 2003 is "2".
Can anyone help?
Can anyone help?
datediff("w",date1,date2)
or....
format(Date2,"ww")-format( Date1,"ww" )
this will give the number of weeks difference
(I have never used datediff to output weeks, try ww alos, let me know)
format(Date2,"ww")-format(
this will give the number of weeks difference
(I have never used datediff to output weeks, try ww alos, let me know)
I think you want:
DateDiff("ww",[DateField1] ,[DateFiel d2])
However - this doesn't work if the first two dates happen to be in different weeks (as they are for March 1st and March 2nd).
What you will need to do is write your own calculation:
WeekDifference: (([Date2]-[Date1])\7)
or something similar. I don't know how the Oracle function works so it's difficult to be more explicit. Can you describe it in more detail if the above does not fulfil your requirement ?
DateDiff("ww",[DateField1]
However - this doesn't work if the first two dates happen to be in different weeks (as they are for March 1st and March 2nd).
What you will need to do is write your own calculation:
WeekDifference: (([Date2]-[Date1])\7)
or something similar. I don't know how the Oracle function works so it's difficult to be more explicit. Can you describe it in more detail if the above does not fulfil your requirement ?
Use the Format function
Format(myDate,"ww")
or the DatePart function
DatePart("ww",myDate)
to get the week of the year (1-51).
Format(myDate,"ww")
or the DatePart function
DatePart("ww",myDate)
to get the week of the year (1-51).
There is no built-in function to calculate the week of the month, but can calculate that by subtracting today's date from the first day of the month:
Function WeekOfMonth(dtIn)
Dim dtFirst As Date
Dim btWeek as Byte
dtFirst = CDate(Month(dtIn) & "/" & Year(dtIn))
btWeek = DatePart("ww", dtIn - dtFirst)
If btWeek > 51 Then
WeekOfMonth=1
Else
WeekOfMonth=btWeek
End If
End Function
Function WeekOfMonth(dtIn)
Dim dtFirst As Date
Dim btWeek as Byte
dtFirst = CDate(Month(dtIn) & "/" & Year(dtIn))
btWeek = DatePart("ww", dtIn - dtFirst)
If btWeek > 51 Then
WeekOfMonth=1
Else
WeekOfMonth=btWeek
End If
End Function
Maybe we did not understand what you are looking for. is it possible you want to know that mar1~mar7 is week 1, mar 8~mar15, week 2...? You should be able to sinply divide the day date by seven to get the week,if there is a remainder, add 1 'cause you're in the next week.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.