473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to convert Date to Week #

What would be the function to convert date to the number of date
for example, 2/14/05 is 45, becuse this is the 45th day of the year.

What would be the function?
Where can I find info on the web about it?

galsaba

Nov 13 '05 #1
3 9000
datepart("y",Date())

--
Terry Kreft
MVP Microsoft Access
"galsaba" <ga*****@aol.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
What would be the function to convert date to the number of date
for example, 2/14/05 is 45, becuse this is the 45th day of the year.

What would be the function?
Where can I find info on the web about it?

galsaba

Nov 13 '05 #2
On Mon, 14 Feb 2005 18:07:50 -0000, "Terry Kreft"
<te*********@mps.co.uk> wrote:

But beware of a bug in oleaut32.dll, which causes this to fail for
some dates, especially around week 53. It bugs me a lot that MSFT has
still not fixed this after knowing about it for several years.
http://support.microsoft.com/default...b;en-us;200299

-Tom.

datepart("y",Date())


Nov 13 '05 #3
galsaba wrote:
What would be the function to convert date to the number of date
for example, 2/14/05 is 45, becuse this is the 45th day of the year.

What would be the function?
Where can I find info on the web about it?

galsaba


The logic for rolling your own day of year would be something like:

Public Function DayOfYear(dtX As Date) As Integer
Dim PriorMonthDays As Variant
Dim boolIsLeap As Boolean

PriorMonthDays = Array(0, 31, 59, 90, 120, 151, _
181, 212, 243, 273, 304, 334)
boolIsLeap = (Year(dtX) Mod 4 = 0) - (Year(dtX) Mod 100 = 0) _
+ (Year(dtX) Mod 400 = 0)
DayOfYear = PriorMonthDays(Month(dtX) - 1) + Day(dtX) + _
boolIsLeap * (Month(dtX) > 2)
End Function

For instance, (DayOfYear(Date()) - 1) \ 7 + 1 would give the week
number based on weeks starting the day of Jan 1. Don't actually do it
this way :-). Follow the advice of the other posters. This example is
merely academic.

James A. Fortune

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
3
by: jerry.ranch | last post by:
I have a need to convert simple dates (i.e. 02/14/2005) to a number, do some math, and convert back to a date. (in a simple query). The math involves adding or substracting days, and days of the...
2
by: Agnes | last post by:
Does .net provide any function for such purpose ? e.g today is 21-10-2004, the week is 43, now I want to get the DATE with (week 42, Monday) Thanks alot
0
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer)...
3
by: Manekurt | last post by:
Hello, does anyone knows how to convert a date, into a number of week of an year? for example mm/dd/yyyy 01/04/2006 convert to 1 (week number 1 of the year) Thanik you
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
5
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.