NULL Values Displayed in a Function

I've got a test page here showing null start and end times where it should say 'tbc'.

Here's the output syntax:

<% if isnull(rs("ca_starttime").Value) then %>tbc<% else %><%=Right("00" & hour(rs("ca_starttime")), 2)%>:<%=Right("00" & minute(rs("ca_starttime")), 2)%><% end if %>

Open in new window


And here's where it's entered:

<% CreateTimeSelectionBox "starttime", NULL, False %>

Open in new window


If someone could please show me exactly what needs to be written in the output syntax it'd be much appreciated.

Many thanks.
UName10Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
<div class="time">At: 00:00</div>
Formatting Time
<%
 if isnull(rs("ca_starttime").Value) then
     response.write "tbc"
     else
     response.write formatdatetime(rs("ca_starttime"),4) '00:00
  end if
%>

If you want to do it the hard way....

<%
 if isnull(rs("ca_starttime").Value) then
     response.write "tbc"
     else
     
      theHour=hour(rs("ca_starttime"))
      theMin=minute(rs("ca_starttime"))
      if theHour<10 then
          theHour="0"&theHour
      end if
      if theMin<10 then
          theMin="0"&theMin
      end if
      response.write theHour&":"&theMin
     
  end if
%>
0
 
UName10Author Commented:
Hi Padas,

Many thanks for the reply. Could you confirm what I should write as the value as I didn't have to do that before?  It's not working with .Value... I.e. It's hours and minutes, but we can't use both.. Just got confused.

Many thanks again.
0
 
Robert SchuttConnect With a Mentor Software EngineerCommented:
It looks to me that there are no real NULL values. Taking padas's code, you could add a replace assuming you will never have an event actually starting or ending at 00:00
response.write Replace(formatdatetime(rs("ca_starttime"),4), "00:00", "tbc") 

Open in new window

However, the NULL database value is in fact used for this specifically, to stand out from values that are accidentally 0 (or 00:00 in this case), so you would need to adjust your insert/update process. I would give you an example but I think it's important to realize first that with your current admin pages (posted in an earlier question) it is not possible to make that distinction. You would need to add a checkbox for example or make it possible to leave the time empty, and of course if you choose 00:00 as empty then using the replace is just as good.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
UName10Author Commented:
Ah yes that's the one - it isn't actually NULL, which is why I was trying to work around it, but knowing it wasn't right.. Yes we have checkboxes for other areas; and makes it more difficult..

Thanks for explaining, that makes sense. I'll have a go with that and see how I get on.

Many thanks.
0
 
UName10Author Commented:
Hi Robert,

Just a question, how do you think would have been the best way to do it; could the admin pages you saw before be written better? Not sure how to explain it, but it does seem we have to do work around too many times.

I.e. if we wanted to make that distinction, what would be the best way to do it?

Could we have a default NULL value for each time select which is changed only when a time is selected, maybe specify it in the function?

This was the admin code bit:

                .addparam "ca_starttime","","'"&getform("starttime_Hour") & ":" & Right("00" & getform("starttime_Min"), 2) & "'"
		.addparam "ca_endtime","","'"&getform("endtime_Hour") & ":" & Right("00" & getform("endtime_Min"), 2) & "'"

Open in new window



I can do the 00:00 for now (although a midnight start or finish wouldn't work then)..

I'll get there in the end!

Many thanks.
0
 
UName10Author Commented:
Thank you both for your replies. As you both contributed, Padas being the main and Robert helping me recall the no NULL values.

The solution works well.
0
 
UName10Author Commented:
Oh and please don't worry Robert about the other queries - I need to learn more I which I'm keen to do. I'll get there...

Many thanks.
0
 
Robert SchuttSoftware EngineerCommented:
There's a link here with another question you asked. If you use a javascript 'popup' to choose the time it may have to be changed completely.

But in general, with your 2 select boxes for hour and minutes, you could for example add a first default option "--" in both, for example with value -1 and in the code check for it and insert NULL in the database. Then the code as you posted initially in this question will work.

One more remark: you may want to check first if the helper class/functions you use are in fact capable of inserting NULL values.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.