SQL PHP HTML ASP JavaScript articles and free scripts to download

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.Mode=adModeRead
conn.ConnectionString = aConnectionString
conn.Open
Set rs =Server.CreateObject("ADODB.Recordset")



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

'Displaying data from the table.

rs.open " select book_id, issue_dt from dt where book_id=5 " , conn
if rs.EOF Then
Response.Write "No Record exist"
Else
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
conn.Close
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
) ON [PRIMARY]
GO

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


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer