Solved

Getting utc date into an asp variable withon an asp acript

Posted on 2008-06-10
7
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

615 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