MySQL
  Home arrow MySQL arrow Page 4 - Two Lessons in ASP and MySQL
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Two Lessons in ASP and MySQL
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 43
    2004-05-10

    Table of Contents:
  • Two Lessons in ASP and MySQL
  • It's a Date!
  • ¿Que Horas Son?
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Two Lessons in ASP and MySQL - Conclusion


    (Page 4 of 4 )

    Anyhow, those are the two lessons I've learned. If at any time I need to work with a full datetime string, I just call both functions, and stitch the two resulting strings together with a space in between. I've found the time function especially helpful in cleaning up user input.
    Here is all the code if you want it:

    '====================
    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


    '====================
    function mysqlTime( t, dir )
    '====================
     
     dim strSuffix, arTime, i, x
     
     t = trim( Lcase( t ) )
     if inStr( t, "pm" ) > 0 OR inStr( t, "am" ) > 0 then
      strSuffix = right( t, 2 )
      t = left( t, inStr( t, strSuffix ) -2 )
      t = trim( t )
     end if 

     for i = 1 to len( t )
      x = mid( t, i, 1 )
      if not isReallyNumeric( x ) and x <> ":" then t = replace( t, x, "" )
     next
     
     arTime = split( t, ":" )
     t = ""
     for i = 0 to 2
      if uBound( arTime ) < i then redim preserve arTime( i )
      
      if i = 0 then
       if dir = 1 then
        if strSuffix = "pm" and cInt( arTime( i ) ) < 12 then
         arTime( i ) = cInt( arTime( i ) ) + 12
        end if
       else
        if cInt( arTime( i ) ) > 12 then
         arTime( i ) = cInt( arTime( i ) ) - 12
         strSuffix   = "PM"
         else
          strSuffix   = "AM"
        end if
       end if
      end if
      
      do until len( arTime( i ) ) = 2
       arTime( i ) = "0" & arTime( i )
      loop
      
      t = t & arTime( i )
      if i < 2 then t = t & ":"
     next
     arTime = null
     if dir = 2 then t = t & " " & strSuffix
     'debug( t )
     mysqlTime = t
    end function


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT