473,546 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing Date values

Hello,

I am comparing two date values, one from a database and one that has
been converted from a hard-coded string into an actual Date type. So
far so good. The problem I'm having is that one of the values comes
from the database, and for existing values it works fine, but if the
date doesn't exist (which will always be the condition when the user
first enters into the form) I am adding logic to my javascript like: if
(dbDate < staticDate || dbDate == ""), then we go into our validation
code. But it isn't working for a new form entry, only if the record
already exists. I think the problem is that because I'm comparing
actual Date values, the (dbDate == "") isn't going to work because ""
is a string value if I'm not mistaken, and this won't work against a
Date value.

So, my question is, what is the best way to check for a non-existent
Date object (value). Should I do something like (dbDate == null)? I'm
just not exactly sure how to check for a non-existent date object. Any
advice would really be appreciated.

Thanks,
KP

Apr 14 '06 #1
5 3793

"Kermit Piper" <di***********@ hotmail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Hello,
So, my question is, what is the best way to check for a non-existent
Date object (value). Should I do something like (dbDate == null)? I'm
just not exactly sure how to check for a non-existent date object. Any
advice would really be appreciated.


if (!dbDate) (I think), will return true if dbDate does not exist.
Apr 14 '06 #2
So, do you mean I should do something like :if (!dbDate) == true ?

Apr 14 '06 #3
Kermit Piper said the following on 4/14/2006 12:25 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
So, do you mean I should do something like :if (!dbDate) == true ?


No, not the == true

if (!dbDate){
//dbDate should exist
}

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 14 '06 #4

"Kermit Piper" <di***********@ hotmail.com> wrote in message
news:11******** **************@ t31g2000cwb.goo glegroups.com.. .
So, do you mean I should do something like :if (!dbDate) == true ?

Like Randy says - (!dbDate) is *already* a boolean expression which is true
or false.
if (!dbDate){
// code if the dbDate does not exist
}
Apr 14 '06 #5
JRS: In article <11************ **********@i39g 2000cwa.googleg roups.com>
, dated Thu, 13 Apr 2006 19:43:43 remote, seen in
news:comp.lang. javascript, Kermit Piper <di***********@ hotmail.com>
posted :
Hello,

I am comparing two date values, one from a database and one that has
been converted from a hard-coded string into an actual Date type. So
far so good. The problem I'm having is that one of the values comes
from the database, and for existing values it works fine, but if the
date doesn't exist (which will always be the condition when the user
first enters into the form) I am adding logic to my javascript like: if
(dbDate < staticDate || dbDate == ""), then we go into our validation
code. But it isn't working for a new form entry, only if the record
already exists. I think the problem is that because I'm comparing
actual Date values, the (dbDate == "") isn't going to work because ""
is a string value if I'm not mistaken, and this won't work against a
Date value.

So, my question is, what is the best way to check for a non-existent
Date object (value). Should I do something like (dbDate == null)? I'm
just not exactly sure how to check for a non-existent date object. Any
advice would really be appreciated.


I doubt whether that's the right question. A coder can, but need not,
want to test whether a coder-created Object exists.

As you've been told, one can test for the non-existence of an Object
called X by using if (!X) ... but that does seem to require
specification of an existing Object which might hold that Object, as in
if (document.all && !document.getEl ementById) ...
testing for all & getElementById .

To test whether a variable is defined, as one might want to do after
if (DoIt) var D = new Date(Str)
, one can use if (typeof D != "undefined" ) .

One must distinguish carefully, after the sole statement
var U
between X, which is a variable that has not been defined, and U, which
is a defined variable whose value has not been defined (its value
therefore being the special value <undefined>).

A Date Object D can certainly not exist (and hence be undefined); I
suspect that if it exists it cannot have an undefined value, though it
can have a conventionally-meaningless value (such as 0 representing
1970-01-01 00:00:00.000 GMT) or a value of NaN, which is what my
attempts to make it contain undefined or Infinity give.

A Date Object can be compared against a String; a direct comparison only
gives true if the string represents that date in the right format, but
testing +new Date(X) == "" is a valid, if silly, way to test if the
Date Object holds zero.

new Date(null) == new Date(0) != new Date(NaN) == NaN
Advice :

1) see signature, lines 2 3 4.
2) test existence before testing value
====

Bug in IE6? lastModified ??

<URL:http://www.merlyn.demo n.co.uk/last-mod.htm> was last uploaded at
close to Tue 2006-02-21 23:36 GMT, genuine time, UK winter, UK then
using GMT. FTP shows the file on the server as being 20060221 23:36, OK
so far. My IE4 here shows the lastModified string as "02/21/06
23:36:05" which (apart from being YY & FFF) is OK - note, that's looking
TODAY, UK Summer, UK = GMT+1.

But, IIRC, the IE6? at the Public Library, looking YESTERDAY, UK Summer,
showed a lastModified string representing an hour later, 00:36:05 on the
22nd Feb (I forget the exact format).

It appears, therefore, that IE6 has read the UTC stored at the server,
and displayed what that civil time would have been if February had been
in Summer.

FWIW, the Library system seems to be US-configured, though by location
it should be UK and by majority user possibly KR.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 14 '06 #6

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

Similar topics

16
13103
by: Donnal Walter | last post by:
I was very surprised to discover that >>> import datetime >>> x = datetime.date(2004, 9, 14) >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15) >>> print x == y True How can these two objects be considered equal? Is there a *general* way to test for date != datetime as well as 4.5 != 4.6?
6
5198
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun Duration (int) - the duration in minutes of the work block. In another table called OvertimeRates I have information about rate multipliers and a...
2
3323
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
12
5527
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the date. Example: Jun 15 How would I go about comparing that to a different date? The purpose of my program is to load a webpage and see if the...
1
1655
by: Adrienne Boswell | last post by:
I have a form which I am letting the user enter more than one event at a time. I need to check whether one date is less than another. If the display to date is earlier than the event date, then of course that's an error. I am getting values like: areaevent_display_from: 09/29/2006, 09/209/2006 areaevent_display_to: 09/29/2006, 08/29/2006...
2
3372
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
4
7395
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system date is retrieved like this: curDt = new Date();
2
1840
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi mister, I have an object with two properties, of type DateTime? (Nullable). Which is the best way for comparing ? The value of datetime can be null, and another value cannot be null, or two values are null, or two values aren't null. if (tarea.Fcprioridad < tarea.Fcentrega)
2
2221
hodgeman
by: hodgeman | last post by:
My second thread on thescripts, so hoping to get the same feedback and help as last time... I've developed an online invoicing and payment system for all my accounts for my web design company. I've been extending the functionality tonight and have come across a problem... I'd like to limit the results based on comparing the total and paid...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.