Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    date functionality Questions

    Exist inverse for below:
    Code:
    <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 ?

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    1) FROM A FORM FIELD:

    Code:
    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:
    Code:
    "#" & request.form("DateField") & "#"
    DATES INTO MySQL: In order to insert them into your MySQL database, you have to do a little date manipulation.

    Code:
    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:
    Code:
    Access: "SELECT * FROM table WHERE date > #" & datefromformfield & "#"
    
    MySQL: "SELECT * FROM table WHERE date > '" & dateThis & "'"   'see above
    For Concatenating strings of data:

    Code:
    ACCESS: datestring = request.form("theMonth") & "/" & request.form("theDay") & "/" & request.form("theYear")
    
    MySQL: datestring = request.form("theYear") & "/" & request.form("theMonth") & "/" & request.form("theDay")
    HTH!
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Exist inverse for "CDate" ?
    "date" INSIDE THE DATABASE how is saved ? excatly like the date compared with ?

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    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.
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •