473,406 Members | 2,816 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,406 software developers and data experts.

Bizarre Day() feature

Hi all,

I'm having a hard time with the Day() function. Basically, it appears
to be picking and choosing which part of a date string it uses to
return the result ...

heres some code :

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%
Function formatDate(dDate)

formatDate=""
If IsNull(dDate) or Trim(dDate)="" Then
Else If IsDate(dDate) Then
If dDate<CDate("January 1, 1901") Then
formatDate=" - - "
Else formatDate=Day(dDate) & " " & MonthName(Month(dDate), true) &
" " & year(dDate)
End If
End If
End If
If formatDate="1 Jan 1900" Then
formatDate="n/a"
End If
End Function

dim sDate1,sDate2

sDate1="12-31-06"
sDate2="07/11/2006"
sDate2="26-12-2006"
Response.Write ("DEFAULT Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
session.LCID=1033
Response.Write ("<BR/>")
Response.Write ("<BR/>")
Response.Write ("Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
session.LCID=2057
Response.Write ("<BR/>")
Response.Write ("<BR/>")
Response.Write ("Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
%>
<P>&nbsp;</P>

</BODY>
</HTML>

OUTPUT################################
DEFAULT Session.LCID=2057
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'

Session.LCID=1033
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'

Session.LCID=2057
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'
/OUTPUT###################################

Notice how it uses the FIRST part of sDate1 to return the day, but the
SECOND part of sDate2

I have tried fiddling with the Locale settings, but whatever they are,
Day("12/26/2006") always returns "26".

Can anyone explain, and hopefully suggest what to do ?

Thanks in advance

Jul 13 '06 #1
3 1463
This is expected 12/26/2006 is always thought to be day 26 of month 12
because it can't be day 12 of month 26...

Note that the problem doesn't lie really with the Day function itself. The
problem is that Day should use a date parameter not a string. As you are
providing a string to this function, the string is first converted to a date
(and it can't be anything else than day 26 month 12). The day is just then
extracted from the date. As a result it always return 26.

Try rather with a date such as 02/03 that can be day 2 of month 3 or day 3
of month 2.

Also my personal preference is to work always with the proper datatype i.e.
to convert a user input string as soon as possible to a real date variable
(or to use a real date variable from the beginning if this is not a user
input)...

--
Patrice

<je*******@hotmail.coma écrit dans le message de news:
11**********************@35g2000cwc.googlegroups.c om...
Hi all,

I'm having a hard time with the Day() function. Basically, it appears
to be picking and choosing which part of a date string it uses to
return the result ...

heres some code :

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%
Function formatDate(dDate)

formatDate=""
If IsNull(dDate) or Trim(dDate)="" Then
Else If IsDate(dDate) Then
If dDate<CDate("January 1, 1901") Then
formatDate=" - - "
Else formatDate=Day(dDate) & " " & MonthName(Month(dDate), true) &
" " & year(dDate)
End If
End If
End If
If formatDate="1 Jan 1900" Then
formatDate="n/a"
End If
End Function

dim sDate1,sDate2

sDate1="12-31-06"
sDate2="07/11/2006"
sDate2="26-12-2006"
Response.Write ("DEFAULT Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
session.LCID=1033
Response.Write ("<BR/>")
Response.Write ("<BR/>")
Response.Write ("Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
session.LCID=2057
Response.Write ("<BR/>")
Response.Write ("<BR/>")
Response.Write ("Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
%>
<P>&nbsp;</P>

</BODY>
</HTML>

OUTPUT################################
DEFAULT Session.LCID=2057
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'

Session.LCID=1033
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'

Session.LCID=2057
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'
/OUTPUT###################################

Notice how it uses the FIRST part of sDate1 to return the day, but the
SECOND part of sDate2

I have tried fiddling with the Locale settings, but whatever they are,
Day("12/26/2006") always returns "26".

Can anyone explain, and hopefully suggest what to do ?

Thanks in advance

Jul 13 '06 #2
je*******@hotmail.com wrote:
Hi all,

I'm having a hard time with the Day() function. Basically, it appears
to be picking and choosing which part of a date string it uses to
return the result ...
To add to what Patrice said: always use a standard date format such as
the ISO standard YYYY-MM-DD

You can use UI gadgets such as calendar controls or dropdown controls to
enforce the standard format.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 13 '06 #3

<je*******@hotmail.comwrote in message
news:11**********************@35g2000cwc.googlegro ups.com...
Hi all,

I'm having a hard time with the Day() function. Basically, it appears
to be picking and choosing which part of a date string it uses to
return the result ...

heres some code :
Enclose a Date 'string' with #

like this

a = CDate(#31/12/2006#)

This is a rarity in VBS, not known by many scripters.

Of course, in my case, the date format (dd-mm-yyyy) between # # is
according to my own locale.
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%
Function formatDate(dDate)

formatDate=""
If IsNull(dDate) or Trim(dDate)="" Then
Else If IsDate(dDate) Then
If dDate<CDate("January 1, 1901") Then
formatDate=" - - "
Else formatDate=Day(dDate) & " " & MonthName(Month(dDate), true) &
" " & year(dDate)
End If
End If
End If
If formatDate="1 Jan 1900" Then
formatDate="n/a"
End If
End Function

dim sDate1,sDate2

sDate1="12-31-06"
sDate2="07/11/2006"
sDate2="26-12-2006"
Response.Write ("DEFAULT Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
session.LCID=1033
Response.Write ("<BR/>")
Response.Write ("<BR/>")
Response.Write ("Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
session.LCID=2057
Response.Write ("<BR/>")
Response.Write ("<BR/>")
Response.Write ("Session.LCID=" & Session.LCID)
Response.Write ("<BR/>")
Response.Write ("Date1=" & sdate1 & ". formatDate(" & sdate1 & ") ='" &
formatDate(sdate1) & "'")
Response.Write ("<BR/>")
Response.Write ("Date2=" & sdate2 & ". formatDate(" & sdate2 & ") ='" &
formatDate(sdate2) & "'")
%>
<P>&nbsp;</P>

</BODY>
</HTML>

OUTPUT################################
DEFAULT Session.LCID=2057
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'

Session.LCID=1033
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'

Session.LCID=2057
Date1=12-31-06. formatDate(12-31-06) ='31 Dec 2006'
Date2=26-12-2006. formatDate(26-12-2006) ='26 Dec 2006'
/OUTPUT###################################

Notice how it uses the FIRST part of sDate1 to return the day, but the
SECOND part of sDate2

I have tried fiddling with the Locale settings, but whatever they are,
Day("12/26/2006") always returns "26".

Can anyone explain, and hopefully suggest what to do ?

Thanks in advance
Jul 14 '06 #4

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

Similar topics

4
by: Alan Little | last post by:
This is very bizarre. Could someone else have a look at this? Maybe you can see something I'm overlooking. Go here: http://www.newsletters.forbes.com/enews/admin/deliver.php4 U: bugtest P:...
9
by: Marcus Sheen [UK] | last post by:
Have done searches for similar questions, but cannot find anything. Nor can I find any resources via Google (Javascript Source etc). Thinking about implementing a topical "On This Day" feature on...
11
by: Frances Del Rio | last post by:
this is so bizarre, and don't even know if this is right place to ask, but don't know where else: about two days I changed webhosting, changed DNS for my domain, francesdelrio.com, now when I...
1
by: Jordan Bruce | last post by:
******************************************************* ONTARIO CANADA INFORMIX USER GROUP (OCIUG) http://www.iiug.org/ociug NEXT MEETING: WEDNESDAY, JULY 14...
36
by: Rolloffle | last post by:
A short time ago my fiancée Kimmy found out that she had gotten pregnant. We had a long, hard talk about what to do, if anything. I was in favour of her getting an abortion, though she was...
0
by: Georg Brandl | last post by:
Hello, it's time for the 7th Python Bug Day. The aim of the bug day is to close as many bugs, patches and feature requests as possible, this time with a special focus on new features that can...
0
by: Georg Brandl | last post by:
Hello, it's time for the 7th Python Bug Day, just before 2.5 alpha 1 is released. The aim of the bug day is to close as many bugs, patches and feature requests as possible, this time with a...
0
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly...
20
by: Jasper | last post by:
I'm stumped. I'm calling a method that has keyword args, but not setting them, and yet one of them starts off with data?! The class definition begins like so: class BattleIntentionAction(...
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: 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
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: 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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.