Solved

Getting utc date into an asp variable withon an asp acript

Posted on 2008-06-10
7
440 Views
Last Modified: 2012-08-13
I need a simple way to get the utc date into my asp script.

In sql select getutcdate() will show the data but how can I bring it to an asp variablw within an asp script?
0
Comment
Question by:robrodp
  • 3
  • 2
  • 2
7 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 21758346
dim cn
dim dt
dim rs

set cn = new ADODB.Connection
ser rs = new ADODB.Recordset

cn.Open "YOUR_CONNECTION_STRING_HERE"
rs = cn.execute("select getutcdate()")

dt = rs.Fields(0).Value ' >dt< contains the date

rs.Close
cn.Close

set rs = Nothing
set cn = Nothing
0
 
LVL 10

Expert Comment

by:bluefezteam
ID: 21758361
This should do it (where connStr is your database connection)
<%
OPTION EXPLICIT
dim connStr, db, rs, sSQL, arr, strUTC
 
connStr = [YOUR CONNECTION STRING]
sSQL = "select getutcdate() as strUTC"
 
set db = server.createobject("adodb.connection")
db.open 
 
set rs = server.createobject("adodb.recordset")
rs.open sSQL, db
 
if not rs.bof and not rs.eof then
	strUTC = rs.fields("strUTC").value
end if
 
rs.close
set rs = nothing
 
db.close
set db = nothing
%>

Open in new window

0
 

Author Comment

by:robrodp
ID: 21761336
Hi bluefez team

I get this error

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/utc.asp, line 9

This is my code:  application("connection") is defined in global.asa

<%
OPTION EXPLICIT
dim connStr, db, rs, sSQL, arr, strUTC
 
connStr = application("connection")
sSQL = "select getutcdate() as strUTC"
 
set db = server.createobject("adodb.connection")
db.open
 
set rs = server.createobject("adodb.recordset")
rs.open sSQL, db
 
if not rs.bof and not rs.eof then
      strUTC = rs.fields("strUTC").value
end if
 
rs.close
set rs = nothing
 
db.close
set db = nothing
%>
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:robrodp
ID: 21761375
Badotz

I get this error:

Microsoft VBScript runtime  error '800a01fa'

Class not defined: 'ADODB'

/utc.asp, line 7

This is my code: application("connection") is defined in global.asa


<%
Conn = application("connection")
dim cn
dim dt
dim rs

set cn = new ADODB.Connection
ser rs = new ADODB.Recordset

cn.Open Conn
rs = Conn.execute("select getutcdate()")

dt = rs.Fields(0).Value ' >dt< contains the date

rs.Close
cn.Close

set rs = Nothing
set cn = Nothing%>
0
 
LVL 29

Expert Comment

by:Badotz
ID: 21761421
set cn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
cn.open connStr
0
 
LVL 29

Expert Comment

by:Badotz
ID: 21761427
Sorry:

cn.open Conn
0
 
LVL 10

Accepted Solution

by:
bluefezteam earned 500 total points
ID: 21761471
try this
OPTION EXPLICIT
dim connStr, db, rs, sSQL, arr, strUTC
 
connStr = application("connection")
sSQL = "select getutcdate() as strUTC"
 
set db = server.createobject("adodb.connection")
db.open connStr
 
set rs = server.createobject("adodb.recordset")
rs.open sSQL, db
 
if not rs.bof and not rs.eof then
	strUTC = rs.fields("strUTC").value
end if
 
rs.close
set rs = nothing
 
db.close
set db = nothing

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question