The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 12:36:58 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: ClassicASP: asp timestamp TO mysql timestamp  (Read 4953 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: April 21, 2007, 09:20:45 AM »

classicASP function(s) to convert windows now() timestamp to a MySQL Timestamp. Its only a 1way function, but its generally only needed in that 1 direction anyway. There would be little reason to ever change from Mysql to ASP timestamps, but actually i havent tried whether formatdate() would do the trick anyway.

Just pass Now() or some other ASP formatted date/time timestamp.

Code:

'============== MySQL TimeStamp Functions next 3
function mysqltimestamp(aspts)
dim thetime,thedate
aspts=cstr(aspts)
thedate=left(aspts,instr(aspts," ")-1)
thetime=right(aspts,len(aspts)-instr(aspts," "))
mysqltimestamp=mysqldate(thedate)&" "&mysqltime(thetime)
end function

function mysqlDate(d)
dim strNewDate
strNewDate = year( d ) & "-" & month( d ) & "-" & day(d)
mysqlDate = strNewDate
end function

function mysqlTime(t)
 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 isNumeric( 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 strSuffix = "pm" and cInt( arTime( i ) ) < 12 then
     arTime( i ) = cInt( arTime( i ) ) + 12
    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
'============== END MySQL TimeStamp Functions
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!