473,473 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional Code if within Date / Time in Database

jschrader
8 New Member
I am trying to write a conditional Statement in ASP based on dates/times in a database entry.

I'm basically a ASP/web designer and try my best to get into the fun coding, so not sure as to the syntax of what I'm trying to do...

The structure I'm working on is

Database Connection
Select DB record occuring "Today" - have this working with BETWEEN statement
DO UNTIL RS.EOF
IF RS(title) < FromTime or >UntilTime Then
<display login HTML code>

ELSEIF RS(title) < UntilTime and > FromTime Then
<display downtime HTML message>

ELSEIF no record for today??
<display login HTML code>

END IF
Loop, close, etc...

This is displaying the maintenance message for the day of the downtime, but when there is none for the day, it displays nothing and I need to specify it to the times of the day specifically

If anyone can think of a better way to do this, I'm all ears, but The current code is below.


Expand|Select|Wrap|Line Numbers
  1. '*****************************************************************************
  2. '    block login function
  3. '*****************************************************************************
  4. sub Block_Login
  5.     dim cn, rs, sql
  6.     set cn=server.CreateObject("ADODB.Connection")
  7.     set rs=server.CreateObject("ADODB.Recordset")
  8. Today = Date
  9. Tomorrow = DateAdd("d",1,Today)
  10. sql="select DowntimeDate, FromTime, UntilTime from Downtime where DowntimeDate BETWEEN '" & Today & "' AND '" & Tomorrow & "'"
  11.     cn.Open Application("database")
  12.     rs.Open sql, cn, 3, 3
  13. %>
  14. <%
  15.     'create variables
  16.     Dim strDate, strTime, strBoth
  17.     'Set variable to todays date (and time)
  18.     'strDate = Date
  19.     strTime = Time
  20.     strBoth = Now
  21. %>
  22.   <%
  23.     DO UNTIL RS.EOF
  24.     IF RS("DowntimeDate") = Today Then
  25.   %>
  26.         <p>System is currently undergoing maintenance
  27.           from <%=rs("FromTime")%> EST until <%=rs("UntilTime")%> EST.
  28.         <p>We apologize for any inconvenience.
  29.  
  30.  <% ELSEIF RS("DowntimeDate") <> Today Then%>
  31.  
  32.         <!-- BEGIN MEMBER LOGIN --> 
  33.           <iframe src="signon.html" 
  34.           name="signon" 
  35.           scrolling="no"></iframe>
  36.           <br>
  37.         <!-- END MEMBER LOGIN -->  
  38.   <% 
  39.     End IF
  40.     RS.MoveNext
  41.     Loop
  42.   %>
  43. <%    
  44.     rs.Close
  45.     cn.Close
  46.     set rs=nothing
  47.     set cn=nothing
  48. end sub
  49.  
Mar 26 '08 #1
8 1963
DrBunchman
979 Recognized Expert Contributor
This is displaying the maintenance message for the day of the downtime, but when there is none for the day, it displays nothing and I need to specify it to the times of the day specifically

If anyone can think of a better way to do this, I'm all ears, but The current code is below.
Hi there,

I'm not sure exactly what you are asking....do you want to only show the maintenance message at certain times of the specified day rather than the whole day?

So you'd store the time that the downtime begins and ends in the database and then display the maintenance message if the current datetime is between those values?

If you can clarify then I'm sure we can help you out.

Dr B
Mar 27 '08 #2
jschrader
8 New Member
yes, that's what I'm trying to do...
Mar 27 '08 #3
DrBunchman
979 Recognized Expert Contributor
This is nice and easy if you make a minor change to your database.

Storing FromTime and UntilTime as DateTime datatypes in the database means you don't have to store the day as a separate column. The DateTime datatype stores, as it's name suggests, a date and a time value.

If you do this then you can change your condition to:

Expand|Select|Wrap|Line Numbers
  1.  
  2. IF RS("FromTime") <= Now And RS("UntilTime") >= Now Then
  3.  
This means that you're site will correctly display the message even if the down time spans two different days.

Does this make sense? Let us know how you get on.

Dr B
Mar 27 '08 #4
jschrader
8 New Member
Thanks much for the time help - got that working great now. changed the datetime formats, now just need to change the backend admin interface so people enter it in the correct format.

There was one more part to this though. This message is replacing the login window when the system is down, so it will need to display it when it is not down. The code is not displaying the login window in the ELSEIF section...

need to account for "no record" or "record outside of range"

Expand|Select|Wrap|Line Numbers
  1.  
  2. IF RS("FromTime") <= Now And RS("UntilTime") >= Now Then
  3.   %>
  4.         currently undergoing maintenance message
  5.  
  6. <% ELSEIF RS("FromTime") > Now And RS("UntilTime") < Now Then%>
  7.  
  8.         <!-- BEGIN MEMBER LOGIN --> 
  9.         Login fields here
  10.         <!-- END MEMBER LOGIN -->          
  11.  
Mar 27 '08 #5
jschrader
8 New Member
and now added the date/time picker to the backend admin to make sure people put it in the correct format. Quick and easy add-on here: http://www.javascriptkit.com/script/...calendar.shtml

but still working on getting it to display the login window when there is not a downtime active
Mar 27 '08 #6
danp129
323 Recognized Expert Contributor
I would write it more like this:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. '*****************************************************************************
  3. '   block login function
  4. '*****************************************************************************
  5. sub Block_Login
  6.     dim cn, rs, sql
  7.     set cn=server.CreateObject("ADODB.Connection")
  8.     set rs=server.CreateObject("ADODB.Recordset")
  9.  
  10.     sql="SELECT FromTime, UntilTime from Downtime WHERE '" & now() & "' BETWEEN FromTime AND UntilTime"
  11.  
  12.     cn.Open Application("database")
  13.     rs.Open sql, cn, 3, 3
  14.  
  15.     If rs.EOF then
  16.         'not during downtime, show your login form
  17.         %><!-- BEGIN MEMBER LOGIN --> 
  18.           <iframe src="signon.html" 
  19.           name="signon" 
  20.           scrolling="no"></iframe>
  21.           <br>
  22.         <!-- END MEMBER LOGIN --><%
  23.     else
  24.         'there's currently downtime show your message
  25.         Response.Write "<p>System is currently undergoing maintenance:<br>"
  26.         While not rs.EOF
  27.             Response.Write rs("FromTime") & " EST until " & rs("UntilTime") & " EST.<br>"
  28.             rs.movenext
  29.         Wend
  30.         Response.Write "<p>We apologize for any inconvenience."
  31.     end if
  32.  
  33.     set rs=nothing
  34.     set cn=nothing
  35. end sub
  36. %>
  37.  
Mar 27 '08 #7
jschrader
8 New Member
Thanks Dan - that worked like a charm.

Everything is working fine now!! even thought it seems my server might be 10 min off from my computer's clock, but guess thats minor.

thanks a ton.

Jeremy
Mar 27 '08 #8
danp129
323 Recognized Expert Contributor
Glad to hear you got it working :)
Mar 27 '08 #9

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

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
1
by: ammarton | last post by:
Hello all...I'm a bit new to working with Macros in Access so forgive me if the terminology I use is not accurate. To preface this, basically I am using a form on a replicated database so the...
3
by: Danny Tuppeny | last post by:
Hi all, I've got a DataList that's bound to a datasource with two columns (well, two that matter). One is called GigDate, and one is called RescheduledFromDate. GigDate doesn't allow NULLs,...
3
by: John | last post by:
Hi I have an app to deal with two companies A & B within a group of companies depending on which database is selected. Is it possible for setup to ask the user at install time which company they...
28
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something...
17
by: Liam.M | last post by:
Hey guys, Forgive me if my question my be alittle silly, but I would very much appreciate and assistance that could be given! My situation is as follows: I have created a Button, and set...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
1
by: Brian | last post by:
I have an ASP.NET page that uses a FormView and SqlDataSource. Within my page I want to change a string if a column within my database record is a certain value. Here is some sample code: ...
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
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.