?
Solved

Updating a datetime field with just the time input

Posted on 2004-11-10
5
Medium Priority
?
206 Views
Last Modified: 2013-12-24
Updating from a form:
(FP2003/SQL 2K SP3)

Have tried this many ways:

update SVC00200 set srvstat=::Status_set::,
Arrivdte='::ArrivedDate::',
ArrivTme=''1900-01-01'+' '+::ArriveTime::',
CompDte='::CompDate::',
CompTme='::CompTime::'
where callnbr='::Callnbr::'

update SVC00200 set srvstat=::Status_set::,
Arrivdte='::ArrivedDate::',
ArrivTme='::ArriveTime::',
CompDte='::CompDate::',
CompTme='::CompTime::'
where callnbr='::Callnbr::'

update SVC00200 set srvstat=::Status_set::,
Arrivdte='::ArrivedDate::',
ArrivTme=::ArriveTime::,
CompDte='::CompDate::',
CompTme='::CompTime::'
where callnbr='::Callnbr::'

ArrivDte and ArrivTme are datetime fields in SQL Server. This is for a website doing remote updates to an application database so I cannot change the field types. Don't ask me why they keep the date in one field and the time in another. Anyway, I can update the date just fine, but get various errors updateing the time from a form:

Syntax error converting datetime from character string
You should provide default values for all form fields that are used in the query.
Or some other various syntax errors.

Depending on how I've got the above code written. The default for both fields is 1900-01-01 00:00:00.000.
And when the fields are updated via the 'heavy' app the ArrivDte changes to 2004-11-11 00:00:00.000 and the ArrivTme changes to 1900-01-01 15:36:00.000.

A straight update statement works fine:

update svc00200
set arrivtme='3:00 PM'
where callnbr='0000031083'

and updates the arrivtme to 1900-01-01 15:00:00.000

The form code is:
<form method="POST" action="callupdated_new.asp">
<p>Call Number:<br>
<input type="text" name="callnbr" size="20" value="<%=request("CALLNBR")%>"></p>
<table border="0" width="41%" id="table1" style="border-collapse: collapse">
<tr>
<td colspan="3" bgcolor="#7288AC">
<p align="center"><b>Date/Time</b></td>
</tr>
<tr>
<td width="102">Arrived:</td>
<td>
<input type="text" name="Arriveddate" size="13" value="1900-01-01"></td>
<td>
<input type="text" name="ArrivedTime" size="11" value="00:00:00"></td>
</tr>
<tr>
<td width="102">Completed:</td>
<td>
<input type="text" name="Compdate" size="13" value="1900-01-01"></td>
<td>
<input type="text" name="CompTime" size="11" value="00:00:00"></td>
</tr>
</table>
<p>New Status:<br>
<font size="2">
<select size="1" name="Status_Set">
<option value="'10E'">Entered</option>
<option value="'15C'">Credit Hold</option>
<option value="'20N'">Notified</option>
<option value="'21A'">Acknowledged</option>
<option value="'30B'">Back Ordered</option>
<option value="'32P'">On P/O</option>
<option value="'45I'">In Transit</option>
<option value="'50D'">Dispatched</option>
<option value="'60A'">Arrived</option>
<option value="'65B'">Parts Arrived</option>
<option value="'70C'">Completed</option>
<option value="'00C'">Canceled</option>
</select></font></p>
<p><input type="submit" value="Update" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>


Any help is appreciated.
0
Comment
Question by:smoothrivers
  • 4
5 Comments
 

Author Comment

by:smoothrivers
ID: 12551293
<%            
Dim mySQL
mySQL= "WHERE ArrivedTime = '" & Request.Form("ArrivedTime") & "'"
Response.write mySQL
Response.end
%>

does return 2:00 PM
0
 
LVL 14

Expert Comment

by:hhammash
ID: 12552010
Hi,

Go into the database in the server
Open the table
go to the time field and put the format
hh:nn:ss  in the format

So when it is submitted by the form as 13:05:22 it will go to the database


hhammash
0
 
LVL 14

Expert Comment

by:hhammash
ID: 12552147
Try this too,

See what I did to the form and the code after the form.  I modified your form and your code:


<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>Call Number</title>
</head>

<body>


<form method="POST" action="TimeFormat.asp">
<p>Call Number:<br>
<input type="text" name="callnbr" size="20" value="<%=request("CALLNBR")%>"></p>
<table border="0" width="41%" id="table1" style="border-collapse: collapse">
<tr>
<td colspan="3" bgcolor="#7288AC">
<p align="center"><b>Date/Time</b></td>
</tr>
<tr>
<td width="102">Arrived:</td>
<td>
<input type="text" name="Arriveddate" size="13" value="1900-01-01"></td>
<td>
<input type="text" name="T1" size="3" value="00">:<input type="text" name="T2" size="3" value="00">:<input type="text" name="T3" size="3" value="00"></td>
</tr>
<tr>
<td width="102">Completed:</td>
<td>
<input type="text" name="Compdate" size="13" value="1900-01-01"></td>
<td>
<input type="text" name="CompTime" size="11" value="00:00:00"></td>
</tr>
</table>
<p>New Status:<br>
<font size="2">
<select size="1" name="Status_Set">
<option value="'10E'">Entered</option>
<option value="'15C'">Credit Hold</option>
<option value="'20N'">Notified</option>
<option value="'21A'">Acknowledged</option>
<option value="'30B'">Back Ordered</option>
<option value="'32P'">On P/O</option>
<option value="'45I'">In Transit</option>
<option value="'50D'">Dispatched</option>
<option value="'60A'">Arrived</option>
<option value="'65B'">Parts Arrived</option>
<option value="'70C'">Completed</option>
<option value="'00C'">Canceled</option>
</select></font></p>
<p><input type="submit" value="Update" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<%          
Dim mySQL
MyT1=request.form("T1")
MyT2=request.form("T2")
MyT3=request.form("T3")
MyTime=MyT1&":"&MyT2&":"&MyT3
mySQL= "WHERE ArrivedTime =" & MyTime
Response.write mySQL
Response.end
%>

</body>

</html>


hhammash
0
 
LVL 14

Accepted Solution

by:
hhammash earned 2000 total points
ID: 12552171
This is for the format of AM and PM

When you did your SQL it is picking up the PM from your PC,  when I tried it on my PC I got 24 Format.  So you have to force it in the entry:


<form method="POST" action="TimeFormat.asp">
<p>Call Number:<br>
<input type="text" name="callnbr" size="20" value="<%=request("CALLNBR")%>"></p>
<table border="0" width="41%" id="table1" style="border-collapse: collapse">
<tr>
<td colspan="3" bgcolor="#7288AC">
<p align="center"><b>Date/Time</b></td>
</tr>
<tr>
<td width="102">Arrived:</td>
<td>
<input type="text" name="Arriveddate" size="13" value="1900-01-01"></td>
<td>
<input type="text" name="T1" size="3" value="00">:<input type="text" name="T2" size="3" value="00"><select size="1" name="T3">
<option>AM</option>
<option>PM</option>
</select></td>
</tr>
<tr>
<td width="102">Completed:</td>
<td>
<input type="text" name="Compdate" size="13" value="1900-01-01"></td>
<td>
<input type="text" name="CompTime" size="11" value="00:00:00"></td>
</tr>
</table>
<p>New Status:<br>
<font size="2">
<select size="1" name="Status_Set">
<option value="'10E'">Entered</option>
<option value="'15C'">Credit Hold</option>
<option value="'20N'">Notified</option>
<option value="'21A'">Acknowledged</option>
<option value="'30B'">Back Ordered</option>
<option value="'32P'">On P/O</option>
<option value="'45I'">In Transit</option>
<option value="'50D'">Dispatched</option>
<option value="'60A'">Arrived</option>
<option value="'65B'">Parts Arrived</option>
<option value="'70C'">Completed</option>
<option value="'00C'">Canceled</option>
</select></font></p>
<p><input type="submit" value="Update" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<%          
Dim mySQL
MyT1=request.form("T1")
MyT2=request.form("T2")
MyT3=request.form("T3")
MyTime=MyT1&":"&MyT2&" "&MyT3
mySQL= "WHERE ArrivedTime =" & MyTime
Response.write mySQL
Response.end
%>


hhammash
0
 
LVL 14

Expert Comment

by:hhammash
ID: 12552177
When you process the form and send the value to the database use the value of mySQL.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question