Solved

NULL Values Displayed in a Function

Posted on 2013-01-26
8
322 Views
Last Modified: 2013-01-27
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.
0
Comment
Question by:UName10
  • 5
  • 2
8 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 400 total points
ID: 38823468
<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
 

Author Comment

by:UName10
ID: 38823945
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
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 100 total points
ID: 38823964
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:UName10
ID: 38823992
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
 

Author Comment

by:UName10
ID: 38824001
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
 

Author Closing Comment

by:UName10
ID: 38824016
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
 

Author Comment

by:UName10
ID: 38824019
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
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38824024
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question