Wrox Programmer Forums
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 1st, 2004, 07:59 AM
Registered User
Join Date: Mar 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default A week of the a year


I´d like to calculate the week of the year of the a date in javascript that I write when I want calculate this. In vbscript exists a function DatePart that it do the same that I´d like to simulate.
How I could simulate this in Javascript?


Old July 1st, 2004, 09:16 AM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts

I would use a server language, preferably PHP. PHP has very explicit date functions.

Coding this would be very difficult in JavaScript.

Does it need to be cilent-side?


Old July 1st, 2004, 09:31 AM
Friend of Wrox
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post


Think this should do it (just pass it a date as a parameter)...

function GetWeek(d){
    var targetDate = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0);
    var dayDiff = (targetDate - new Date(d.getFullYear(), 0, 1, 0, 0, 0)) / (24 * 60 * 60 * 1000);
    return Math.ceil((dayDiff - targetDate.getDay()) / 7) + 1; 


Similar Threads
Thread Thread Starter Forum Replies Last Post
Week of Year kiwibey ASP.NET 2.0 Professional 0 June 3rd, 2007 11:14 PM
How to calculate "last year"? ihsail Linux 1 December 1st, 2005 06:03 PM
Year Validation jputhra SQL Server 2000 1 December 10th, 2004 10:03 AM
Fiscal Year jemacc SQL Server 2000 4 October 7th, 2004 03:05 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.