This is code I found on the web to convert dates in ASP format that would normally be sent to an Access or MS SQL database, DD-MM-YYYY to a format that is compatible for MySQL which needs YYYY-MM-DD...
'====================
function mysqlDate( d, dir )
'====================
'if not isDate( d ) then call errorMessage( d & " is not a date " )
'if not isDate( d ) then exit function
if not isDate( d ) then d = Date()
dim strNewDate
select case dir
case 1 '=== store in db
strNewDate = year( d ) & "-" & month( d ) & "-" & day( d )
case 2 '=== use with asp
strNewDate = month( d )& "/" & day( d ) & "/" & year( d )
end select
strNewDate = cDate( strNewDate )
mysqlDate = strNewDate
end function
'/////////////////////////
//////////
//////
strDate = FormatDateTime(now())
strDay = Day(strDate)
If Len(strDay) = 1 Then
strDay = "0" & strDay
End If
strMonth = Month(strDate)
If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If
strYear = DatePart("yyyy", strDate)
OutputDate = "('" & strYear & "-" & strMonth & "-" & strDay & "')"
'/////////////////////////
///////
Function dateConvert(conv_mode, conv_date)
'convert date to and from ASP and MySQL date modes
'i.e. ASP mode: MM/DD/YYYY; MySQL mode: YYYY-MM-DD
Dim newDate
If Not isDate(conv_date) Then conv_date = Date()
Select Case conv_mode
Case 1 'resulting date will be in MySQL format
newDate = year(conv_date) & "-" & month(conv_date) & "-" & day(conv_date)
Case 2 'resulting date will be in ASP format
newDate = month(conv_date) & "/" & day(conv_date) & "/" & year(conv_date)
End Select
newDate = CDate(newDate)
dateConvert = newDate
End Function
'/////////////////////////
//////////
//////////
/////
I found this above code to convert dates being entered into MySQL table through .ASP page, but I am having such trouble trying to get a date entered in my MySQL table. I keep getting 0000-00-00 entered instead of my date.
here is more of my code:
'/////////////////
My Form:
'//////////////////
<form name='Upload' method='post' ENCTYPE='multipart/form-da
ta' action='mysql_downloadadmi
n.asp?mode
=uploadpro
cess'>
<input type='hidden' name='txtDate' value='<%=date()%>'>
<table width="121%" height="277" align="center" cellpadding="3">
<tr>
<td width="284" valign="top"><b>Select a file:</b><br>
<input type='FILE' name='txtFile'> </td>
<td width="18" valign="top"> </td>
<td width="336" valign="top"><b>Version:</
b> <br>
<input type='text' name='txtVersion'> </td>
</tr>
<tr>
<td valign="top"><b>Title:</b>
<br>
<input name='txtTitle' type='text' size="40"> <br> </td>
<td valign="top"><img src="../spacer.gif" width="18" height="32"></td>
<td valign="top"><b>Access:</b
><br>
<select name="txtAccess">
<option value=""> - Choose access level - </option>
<option value="Internal">Internal<
/option>
<option value="External">External<
/option>
<option value="Development">Develo
pment</opt
ion>
<option value="Private">Private</o
ption>
</select></td>
</tr>
<tr>
<td height="42" colspan="2" valign="top"><b>Type:</b><
br>
<select name="txtSuffix">
<option value=""> - Choose Type - </option>
<option value="<%=strSuffix%>"><%=
strSuffix%
></option>
<option value="Service Pack">SP</option>
<option value="alpha">α - Alpha</option>
<option value="beta">β - Beta</option>
<option value="RC">RC</option>
</select>
<input type='text' name='txSuffixText' size='3' value='<%=strSuffixText%>'
>
</td>
<td rowspan="3" valign="top"><b>Notes:</b>
<br>
<textarea name='txtDescription' rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td height="45" colspan="2" valign="top"><strong>BAAN Product ID:</strong><br>
<input type="text" name="txtBaanProdID"></td>
</tr>
<tr>
<td height="6" colspan="2"><b>Author:</b>
<br>
<input type="text" name="txtAuthor"></td>
</tr>
<tr>
<td><b>Group:</b> <br>
<input type="text" name="txtGroup"></td>
<td></td>
<td> </td>
</tr>
<input type='hidden' name='txtID' value='<%=strID%>'>
<tr>
<td><div align="right">
<INPUT name="image" type=image onClick='parent.history.ba
ck(); return false;' value='Back' src=images/back.gif align="middle">
</div></td>
<td><div align="center"> </div></td>
<td><input type='image' src='images/submit.jpg' name='Submit2' value='Enter' alt='Enter'></td>
</tr>
</table>
</form>
'/////////////////////////
//////////
//////////
//////////
/
Then my UploadProcess ASP works like this:
'/////////////////////////
//////////
//////////
//////////
function fieldReplace(item)
item = replace(item, "'", "''")
item = replace(item, "%", "%")
item = replace(item, vbcrlf, "<br>")
fieldReplace = item
end function
If Request.querystring("mode"
) = "uploadprocess" then
set adoCon = Server.CreateObject("ADODB
.Connectio
n")
adoCon.Open "Driver=" & dbDriver & "; Database=" & dbDatabase & "; Uid=" & dbUser & "; Pwd=" & dbPassword & ";"
Set rsSettings = Server.CreateObject("ADODB
.Recordset
")
strSettingsSQL = "SELECT sitelink FROM tblsettings"
rsSettings.Open strSettingsSQL, adoCon
Set Uploader = New FileUploader
Uploader.Upload()
strTitle = Uploader.Form("txtTitle")
strDate = Uploader.Form("txtDate")
strAuthor = Uploader.Form("txtAuthor")
strAccess = Uploader.Form("txtAccess")
strVersion = Uploader.Form("txtVersion"
)
strDescription = Uploader.Form("txtDescript
ion")
strSuffix = Uploader.Form("txtSuffix")
strSuffixText = Uploader.Form("txtSuffixTe
xt")
strBaanProdID = Uploader.Form("txtBaanProd
ID")
strGroup = Uploader.Form("txtGroup")
strTitle = fieldReplace(strTitle)
strDate = fieldReplace(strDate)
strAuthor = fieldReplace(strAuthor)
strAccess = fieldReplace(strAccess)
strVersion = fieldReplace(strVersion)
strDescription = fieldReplace(strDescriptio
n)
strSuffix = fieldReplace(strSuffix)
strSuffixText = fieldReplace(strSuffixText
)
strBaanProdID = fieldReplace(strBaanProdID
)
strGroup = fieldReplace(strGroup)
If Uploader.Files.Count = 0 Then
Response.Write "File(s) not uploaded."
Else
For Each File In Uploader.Files.Items
File.SaveToDisk Server.MapPath("files")
numSize = File.FileSize
strURL = rsSettings("sitelink") & "/files/" & File.FileName
strSQL = "INSERT INTO tbldownload (downloadtitle, downloadDate, downloadsize, downloadAuthor, downloadAccess, downloadVersion, downloadSuffix, downloadSuffixText, downloadBaanProdID, downloadDescription, downloadurl, downloadGroup)VALUES('" & strTitle & "','" & strDate & "','" & numSize & "','" & strAuthor & "','" & strAccess & "','" & strVersion & "','" & strSuffix & "','" & strSuffixText & "','" & strBaanProdID & "','" & strDescription & "','" & strURL & "','" & strGroup & "')"
adoCon.Execute(strSQL)
Next
End If
Set adoCon = Nothing
Response.Redirect"mysql_do
wnloadadmi
n.asp?mode
=listdownl
oad"
End If
I just want the date to be entered. This system needs to have a date when the file is added. All that I am getting in my date column in my database is 0000-00-00
I see the functions I found to convert dates and they look like they might work, but I don't know where to enter them into my code and how to enter them.
CAN ANYONE HELP!!!!