473,748 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Options for Validating a Date Value?

Surprisingly (at least to me), there doesn't seem to be a built-in
function to validate a date value (like, say, is_date()). Given that,
is there a best practice for determining whether a value is a valid
date/time? The values I need to test will likely be unix timestamp
values and I need to be able to distinguish them as date/time values
from other integer/numeric values.

What I'm trying to do is use reflection to iterate over the properties
of an object and insert them into database fields based on their type
(integers in an INT field, strings in a VARCHAR field, date/time
values in a DATETIME field). Most are fairly straightforward , but I'm
not sure how to consistently and accurately identify a datetime value.

Any thoughts would be appreciated.

Rob
Nov 24 '07 #1
8 1955
Rob Wilkerson wrote:
Surprisingly (at least to me), there doesn't seem to be a built-in
function to validate a date value (like, say, is_date()). Given that,
is there a best practice for determining whether a value is a valid
date/time? The values I need to test will likely be unix timestamp
values and I need to be able to distinguish them as date/time values
from other integer/numeric values.

What I'm trying to do is use reflection to iterate over the properties
of an object and insert them into database fields based on their type
(integers in an INT field, strings in a VARCHAR field, date/time
values in a DATETIME field). Most are fairly straightforward , but I'm
not sure how to consistently and accurately identify a datetime value.

Any thoughts would be appreciated.

Rob
Unix timestamps are just integers. You can't differentiate them.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 24 '07 #2
On Nov 24, 3:56 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>
Unix timestamps are just integers. You can't differentiate them.
Yeah, I was hoping that you all (as seasoned php developers) had
figured out some fancy technique for identifying one as a date value
rather than as an integer. :-) Guess I'll have to come up with a new
plan...

Thanks.
Nov 24 '07 #3
What about first converting the integer to a date using the "date"
function. From here you can see if it validates to a real date by
using PHP's built-in "checkdate" function, and then go from there. You
will have to do additional testing if the converted integer from the
first step turns out to be "12-31-1969," as most numbers 5-digits or
less will.

ie

date('m-d-Y',12345) returns "12-31-1969"


On Nov 24, 2:56 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Rob Wilkerson wrote:
Surprisingly (at least to me), there doesn't seem to be a built-in
function to validate a date value (like, say, is_date()). Given that,
is there a best practice for determining whether a value is a valid
date/time? The values I need to test will likely be unix timestamp
values and I need to be able to distinguish them as date/time values
from other integer/numeric values.
What I'm trying to do is use reflection to iterate over the properties
of an object and insert them into database fields based on their type
(integers in an INT field, strings in a VARCHAR field, date/time
values in a DATETIME field). Most are fairly straightforward , but I'm
not sure how to consistently and accurately identify a datetime value.
Any thoughts would be appreciated.
Rob

Unix timestamps are just integers. You can't differentiate them.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
Nov 24 '07 #4
>What about first converting the integer to a date using the "date"
>function. From here you can see if it validates to a real date by
using PHP's built-in "checkdate" function, and then go from there. You
I believe this check will *always* pass if the number fits in a 32-bit
integer, rendering the check somewhat pointless.

Do you have any additional constraints on this date other than that
it's a valid date? Like it's supposed to be in the future, in the
past, or reasonably close (e.g. within a year) of the current time?
Nov 24 '07 #5
Rob Wilkerson wrote:
On Nov 24, 3:56 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Unix timestamps are just integers. You can't differentiate them.

Yeah, I was hoping that you all (as seasoned php developers) had
figured out some fancy technique for identifying one as a date value
rather than as an integer. :-) Guess I'll have to come up with a new
plan...

Thanks.
Nope, there is no difference.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 24 '07 #6
Rob Wilkerson wrote:
On Nov 24, 3:56 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Unix timestamps are just integers. You can't differentiate them.

Yeah, I was hoping that you all (as seasoned php developers) had
figured out some fancy technique for identifying one as a date value
rather than as an integer. :-) Guess I'll have to come up with a new
plan...

Thanks.
Can you tell what your INT data is going to be? Can you tell what is
the oldest date is going to be? You could possibly hack it if your
integer data falls within a certain range you could make some assumptions:

If each of your INTeger data is less than 1000000000 (ten digits, 1
billion) which is a unix timestamp equal to Sept. 08, 2001 @ approx
9:46pm, then you could possibly assume that anything above this would be
a timestamp.

Ugly I know...

Norm
Nov 25 '07 #7
NC
On Nov 24, 12:44 pm, Rob Wilkerson <r.d.wilker...@ gmail.comwrote:
>
Surprisingly (at least to me), there doesn't seem to be a built-in
function to validate a date value (like, say, is_date()). Given that,
is there a best practice for determining whether a value is a valid
date/time? The values I need to test will likely be unix timestamp
values and I need to be able to distinguish them as date/time values
from other integer/numeric values.
A Unix timestamp is an integer, so any integer is by definition a
valid Unix timestamp and thus requires no validation.

Cheers,
NC

Nov 25 '07 #8
On Nov 25, 12:25 am, NC <n...@iname.com wrote:
A Unix timestamp is an integer, so any integer is by definition a
valid Unix timestamp and thus requires no validation.
In my case, I wasn't really looking to validate the value as much as
distinguish it as a date/time value. After reading the feedback
everyone provided, I came to realize that it doesn't matter. It
doesn't really matter how I persist the value as long as the class
instance itself knows what to do with the value when it's retrieved.
I was over-thinking things a bit. :-)
Nov 25 '07 #9

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

Similar topics

12
6557
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
5
2386
by: Astra | last post by:
Hi All I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004 .... 2020), do you know of any js validation check I can use to check whether these values are older than today's date so that I can bring up a warning, eg user chooses 04 and 2003 or 01 and 2004 OnClick a validate script sees that either of the above are older than
1
2903
by: panche | last post by:
I'm developing a fairly simple user control that has two textboxes for date/time entry (a from date/time and a to date/time). One of my requirements is that there should be no button that sets these values (i.e., no button to cause a postback). The problem I'm having is that I need a number of validations to be performed on the data entry, but I don't know how to do this without having the user control/page posted back to the server. ...
2
2451
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to populate the combo (for a list of 2500). Can anybody optimize the code. I tried Duffs devise instead of 'for loop', but no improvement.
4
1954
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I want to change or add options to a drop down box, I then have to copy that to the other 11 boxes. Would it be possible to define the options once, and then have all of the drop down boxes get their options from the single list? Here is my...
2
2183
by: SONIQ | last post by:
Using javascripts to validate this form. Basic operation, when a user clicks the submit order button, the javascript code must validate everything entered by the user. Please help finnish this form. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
1
1534
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
I have a textBox Where I type date. I want to validate it. Im using customValidate controls. I have this function in my code behind page void DatesValidate(object source, ServerValidateEventArgs e) { if (Convert.ToDateTime(e.Value) <= DateTime.Now) { e.IsValid = false; this.lblAddUsers.Text = "The Proxy is already expired"; }
7
2443
by: mc | last post by:
I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client. I have created a new control as below:- public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); }
8
13743
vs2k8
by: vs2k8 | last post by:
Hello guys, New to this forum and new to access programing, my issue is I am comparing 2 date fields, I have to validate that Order Rcvd Dt should be less then Ord Comp date and Order Comp date cannot be null. So I written a function to validate the field which is shown below, If I write before update on Order_comp_date field then I get run time error message : You must save the field before you execute setfocus method Private Sub...
0
8984
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4593
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.