473,396 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What values can a datetime data type hold other than date and time??

Hi folks,

I have designed a webpage using asp, i have a text box with a calender in the page from which the user will select a date. since the date field is not mandatory, if this field is left un-entered/blank then the SQL server will automatically inserts the default date "1/1/1900" while insertion to the Database.

I am trying to eliminate/replace the default date getting stored to the database while the date field left blank (Note: Per requirement i cannot make the date field manadatory).

So i am trying to write a condition to check if the date field is empty and if YES then replace some value, before the code inserts the form values to the Database.

if date_field = "" then
date_field = ""
end if

The above code still inserts dafault since the datetime data type itself will not allow blank but if i say date_field = 0 then the system errors out since the data type is datetime. Please help with this issue.

Thanks in advance

Regards,
chandru
Oct 26 '09 #1
3 3089
ck9663
2,878 Expert 2GB
Options:
1. On your front-end (ASP) check if the object value is empty. If it is, store NULL.
2. On the database, use NULL as default value of the column on your table.

Either case, you need to allow NULL value to be stored in the column.

Happy coding!!!

--- CK
Oct 26 '09 #2
Hi Ck,

Thanks for the reply. I understood your first point.

In your second point i have a slight re-confirmation to make so that we both are on the same page.

In your second point of allowing NULLS, do you mean to change the property of the column from not null to null so that accepts Null values... Please advise.

Also if there is any way? that we can make SQL server not to automatically stores its default values. Thanks in advance.. waiting for your response

regards,
Chandru
Oct 27 '09 #3
ck9663
2,878 Expert 2GB
@chandhseke
Yes.

@chandhseke
If you specify a default value on the column of a table, it will store that default if you don't specify any value that will be stored to it (ie, not included on the column list on the INSERT INTO clause). If you specify a value, it will store the value you specified, not the default value.

To avoid storing the default, always include it on your INSERT INTO column list and specify a value on the SELECT or VALUES clause.

Happy Coding!!!

--- CK
Oct 27 '09 #4

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

Similar topics

2
by: Tatiana Zadiraka | last post by:
I use DB2 8.1 with FixPack 5. In command line for sql I get all DATE columns only in MM-DD-YYYY format. Of course, DATE('20-12-2003') gives me an error SQL0181N The string representation of a...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
1
by: scj | last post by:
Hi all, I need to determine the exact type of DateTime column(*) in an Access 97 database. I'm able to do this with an Access 2 database. With ADO.Net and VB.Net (**), I do something like...
3
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
1
by: Ugur Ekinci | last post by:
Hi , I have two Sql Server 2000 on seperate machines , First one accepts datetime format like ("dd.MM.yyyy hh:mm:ss") And Second one accepts datetime format like ("MM.dd.yyyy hh:mm:ss") 1-...
5
by: Takeadoe | last post by:
Gang - I'm generating date and time variables from scanned forms. Currently, the date and time values are as follows: 06/26/2006 and 11:30 AM. I've written VBA code to combine them into a...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
1
by: remya1000 | last post by:
I’m using VB.net 2003 application program. I am trying to do a select statement whereby I'm searching between 2 datetime values that are being stored as datetime. records are stored inside...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
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...

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.