Solved

Getting utc date into an asp variable withon an asp acript

Posted on 2008-06-10
7
436 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now