Date & time field data updating

We will try to read a date and time field and populate the data in a text box. Then we can ask the users to edit the date and time value and update the record. Here we are asking users to change the data which has to be stored in a date and time field, so we have to check the entered data is a valid date and time or not. We will be using the IsDate to validate the date and time data entered by user. One if condition checking we will do and it is passed ( true ) then only the query to update the record will be executed, else the corresponding error message will be displayed.

Here we are using one table name dt which has three columns ( fields ), book_id one auto MSSQL increment identity column , issue_dt one date and time field & return_dt one date and time field ( note that date and time fields here are not short date and time field.) . We will try to collect a record with book_id = 5 and update the same record. You can download the table structure with data at the end of this page.

Dim conn,rs,SQL,dtm,dtm2,dtt,todo

Set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString = aConnectionString
Set rs =Server.CreateObject("ADODB.Recordset")

if(todo="update") Then
Response.Write dtt
if isDate(dtt) Then " update dt set issue_dt='" & dtt & "' where book_id=5 " , conn
Response.Write " Wrong Date format "
End if
End if

'Displaying data from the table. " select book_id, issue_dt from dt where book_id=5 " , conn
if rs.EOF Then
Response.Write "No Record exist"
Response.Write "<form method=post action='' ><input type=hidden name=todo value=update><input type=text name =dtt value= '" & rs("issue_dt") & "'><input type=submit value=Update></form>"
Response.Write "After the update <br>Book Id: " & rs("book_id") &" Issude Date: " & rs("issue_dt")
End if

Set rs = Nothing
Set conn = Nothing

Table structure is here

CREATE TABLE [dbo].[dt] (
[book_id] [int] IDENTITY (1, 1) NOT NULL ,
[issue_dt] [datetime] NOT NULL ,
[return_dt] [datetime] NOT NULL

Table data is here

3,2007-08-23 00:00:00,2007-09-25 00:00:00
4,2007-12-15 00:00:00,2008-01-02 00:00:00
5,2007-07-05 19:59:56,2007-07-20 19:54:56

Be the first to post comment on this article :

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 All rights reserved worldwide Privacy Policy Disclaimer