473,413 Members | 1,778 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,413 software developers and data experts.

vbscript date error

I have a script that generates a calendar. It's worked fine for two or three years now, but at the beginning of this month, the days were incorrect. It displays February 1, 2008 as being a Wednesday, when it was a Friday.

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. dim startday
  2. startday = weekday(month & "/" & day & "/" & year)
  3. select case startday
  4.   case 1
  5.     'Sunday
  6.   case 2
  7.     'Monday
  8.   'etc.
  9.  
Instead of evaluating to 6, or Friday, weekday("2/1/2008") evaluates to 4, or Wednesday. However, weekday("1/31/2008") evaluates to 5, or Thursday. I checked the values for month, day, and year, and they are 2, 1, and 2008 respectively when the code fires.

I even tried weekday("2/1/2008") on w3schools in the Try It editor, and it evaluated to 3 as well.

Any ideas?
Feb 11 '08 #1
3 1296
kadghar
1,295 Expert 1GB
yes, it's because VB it's a "smart" dates reader, so if you write 12/31/07, since 31 cannot be the month, it assumes you're talking about December 31st.
But if you write "2/1/2008" i'd say it wont use mm/dd/yyyy but dd/mm/yyyy and actually January the 2nd was wednesday.

i'd recommend you to write a little function like:
Expand|Select|Wrap|Line Numbers
  1. public function myMonth(byval mnth as integer) as string
  2. select case mnth
  3.     case 1: myMonth = "Jan"
  4.     case 2: myMonth = "Feb"
  5.     case 3: myMonth = "Mar"
  6.    '(...)
  7. end select
  8. end function
and instead of:
startday = Weekday(month & "/" & day & "/" & year)
use:
startday = Weekday(myMonth(month) & "/" & day & "/" & year)

This might solve many date problems, but will create you a language issue. This code wont run in not-english versions.
HTH
Feb 11 '08 #2
That worked perfectly. Thanks! :D
Feb 12 '08 #3
Killer42
8,435 Expert 8TB
To avoid the language issues, don't bother with the month name. Just use DateSerial() function, which accepts the year, month and day in a clearly defined sequence.

For example...
startday = Weekday(DateSerial(Year, Month, Day))

By the way, I recommend changing the names of your variables. Year, Month and Day are the names of functions in VB.
Feb 13 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
1
by: g_sharad | last post by:
I guess this is a very old problem, but this keeps bugging many ppl in many ways. I am facing the problem with the SQL query >>>> Insert Into DailySalesReport (hoautoid, dsdate, dsreport,...
1
by: JNariss | last post by:
Hello, I have created a connection to my Access database with Dreamweaver and made a simple form with 4 fields. The code behind this form was/is: <%@LANGUAGE="VBCRIPT" CODEPAGE="1252"%>...
7
by: divya | last post by:
What is an equivalent TimeSerial() function of VBscript in the Java Script?? I have two variables hour and minutes. Timeserial(hour,minutes) returns the time hour : minutes. But I want to do...
3
by: easter | last post by:
I have inherited an ASP site and am new to ASP. Part of the site allows the client to update event information about their centre. When they try to add a new event, the following error occurs: ...
11
by: remya1000 | last post by:
While running the program, i'm getting this error Microsoft VBScript compilation error '800a0401' Expected end of statement /admin/currentmonth.asp, line 26 strSQL = "SELECT...
1
by: monika | last post by:
Hello: I have Error Type: Microsoft VBScript runtime (0x800A000D) Type mismatch: '' /OnlineLIB/BNosearch1.asp, line 32 The error happened at this line:bookno = chr(bookno) The code like...
2
by: kevinr | last post by:
Hi, I am brand new to VB, and I am trying to deploy Office 2007 on my network here at work. We used part of this script to do another deployment, and I have taken pieces and tried to edit for this...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.