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

DatePart

le0
Hello guys,

Is there anything wrong with my code (see below) bcoz when 10p-6a shift my
browser returns the error cannot be a zero-length string. Im wondering why,
bcoz the 2 other shift works perfectly.

<%
'Shift: 6a-2p
if DatePart("h", Now()) 5 And DatePart("h", Now()) < 14 then
ShiftID = "A"
end if

'Shift: 2p-10p
if DatePart("h", Now()) 13 And DatePart("h", Now()) < 22 then
ShiftID = "B"
end if

'Shift: 10p-6a
if DatePart("h", Now()) 21 And DatePart("h", Now()) < 6 then
ShiftID = "C"
end if
%>
Aug 11 '06 #1
2 2104
le0 wrote:
'Shift: 10p-6a
if DatePart("h", Now()) 21 And DatePart("h", Now()) < 6 then
ShiftID = "C"
end if
When is something greater than 21 AND less than 6? Unlike your other
conditions, you can use OR for this one:

If DatePart("h",Now) 21 OR DatePart("h",Now) < 6 Then
ShiftID = "C"
End If

Of course, this might not be a bad place for a Select Case Statement:

Select Case DatePart("h",Now)
Case 6,7,8,9,10,11,12,13 ShiftID = "A"
Case 14,15,16,17,18,19,20,21 ShiftID = "B"
Case Else ShiftID = "C"
End Select

And if you really want to shorten it, this will handle all three of your
conditions:

Shifts = Array("A","B","C")
ShiftID = Shifts((DatePart("h",Now)+18)\8 Mod 3)
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Aug 11 '06 #2
le0
Thanks Dave youre d'best =)

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:12*************@corp.supernews.com...
le0 wrote:
> 'Shift: 10p-6a
if DatePart("h", Now()) 21 And DatePart("h", Now()) < 6 then
ShiftID = "C"
end if

When is something greater than 21 AND less than 6? Unlike your other
conditions, you can use OR for this one:

If DatePart("h",Now) 21 OR DatePart("h",Now) < 6 Then
ShiftID = "C"
End If

Of course, this might not be a bad place for a Select Case Statement:

Select Case DatePart("h",Now)
Case 6,7,8,9,10,11,12,13 ShiftID = "A"
Case 14,15,16,17,18,19,20,21 ShiftID = "B"
Case Else ShiftID = "C"
End Select

And if you really want to shorten it, this will handle all three of your
conditions:

Shifts = Array("A","B","C")
ShiftID = Shifts((DatePart("h",Now)+18)\8 Mod 3)
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.

Aug 11 '06 #3

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

Similar topics

3
by: David | last post by:
Hi Group, i am trying to use the DatePart function on my SQL2000 database. I have a table called visitors with a field called DateTimeEntrance which is filled everytime a visitor enters the site....
2
by: Tipple | last post by:
I'm trying to increment between the end of lunch and the end of the day. The code below is returning a datePart of 13 instead of 1 (for 1:00:00 PM) and 14 instead of 2:00:00 PM etc.. If...
2
by: sdowney717 | last post by:
The field itemdate is a datetime field in sqlserver2000 DB This works fine: Select Id From BookData Where (MONTH(itemdate) = '01') and (DAY(itemdate) = '02') and (YEAR(itemdate) = '2005') order...
3
by: david liu | last post by:
i have a date (in date/time format with input mask) in access 2002. field date: 01/01/1970 what i want: 010170 (i.e. mmddyy) i used: DatePart("m",) + DatePart("d",) +...
2
by: Aaran76 | last post by:
I am creating a booking system in ASP.Net with VB and a MSSQL backend. I am having problems knowing where to begin with a particular part of the system. Bookings can only be made in weekly...
3
by: S. van Beek | last post by:
Dear reader, With DatePart() you can subtract the year or the week from a date field with: DatePart("yyyy";) for the year
2
by: troddy | last post by:
I am using the DatePart funtion in a query to extract the day, month and year in separate fields in a query. The function works fine but I am only getting a number for the month even if the field...
10
by: Mika M | last post by:
Hi! I'm converting some methods of VB-class into C#-class for another project. It's quite easy, but when converting method which returns last week number of the entered year I got problems. The...
3
by: grabit | last post by:
Hi Peoples I am having probs with the datepart function with a query.What i want is to get all listings made in any month in any year ie May 2007 i have 2 drop down boxes to select the listedmonth...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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.