...

View Full Version : date functionality Questions



lse123
07-27-2007, 06:03 PM
Exist inverse for below:

<html>
<body>

<script type="text/vbscript">

d="April 22, 2001"
if IsDate(d) then
document.write(CDate(d))
end if

</script>

</body>
</html>

---------------------------------------------------
How I compare Dates below:
1) get from a form field in format mm/dd/yyyy
with
2) dates from Access db table field
or
2) dates from MySQL db table field ? I mean like

strSelection = "SELECT * FROM table WHERE date >" & datefromformfield
---------------------------------------------------
When I get dd , mm and yyyy from drop-down menus[separatelly] what functions I must use to constract a date string to be compared like WHERE STATEMENT above ?

Daemonspyre
07-27-2007, 06:33 PM
1) FROM A FORM FIELD:



If Not IsDate(request.form("your_field")) then
Error = "You have entered an invalid date. Please try again"
Else
'do nothing, date is fine.
End If


2 & 3) Dates from Access and MySQL are displayed based on your Regional Settings. However:


DATES INTO ACCESS:
"#" & request.form("DateField") & "#"

DATES INTO MySQL: In order to insert them into your MySQL database, you have to do a little date manipulation.



If IsDate(request.form("your_field")) then
theField = request.form("your_field")
dateThis = datepart("yyyy",theField) & "-" & datepart("m",theField) & "-" & datepart("d",theField)
end if
'
'
'Note: Some people use YEAR(request.form("your_field")), DAY(...), MONTH(...). It's up to you which one you want to use.


SELECT STATEMENT:


Access: "SELECT * FROM table WHERE date > #" & datefromformfield & "#"

MySQL: "SELECT * FROM table WHERE date > '" & dateThis & "'" 'see above


For Concatenating strings of data:


ACCESS: datestring = request.form("theMonth") & "/" & request.form("theDay") & "/" & request.form("theYear")

MySQL: datestring = request.form("theYear") & "/" & request.form("theMonth") & "/" & request.form("theDay")

HTH!

lse123
07-28-2007, 10:49 AM
Exist inverse for "CDate" ?
"date" INSIDE THE DATABASE how is saved ? excatly like the date compared with ?

Daemonspyre
07-28-2007, 03:23 PM
In MSAccess, it's stored based on the Regional Settings on your computer/Server. So, if you have US Date formats, it is stored as MM-DD-YYYY. If you have GB Dates, it's DD-MM-YYYY. Other EU dates are YYYY-MM-DD.

In MySQL, it's stored as YYYY-MM-DD.

There is not an "inverse" for cDate. cDate converts a string of text or numbers to a date. If it cannot convert, then it returns NULL.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum