Solved

Getting utc date into an asp variable withon an asp acript

Posted on 2008-06-10
7
441 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
Technology Partners: 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!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reg Exp to extract Url from string asp 12 61
Read text on Table 7 50
Outlook Macro to delete emails not meeting keywords 56 118
VBA code for SubFolders 11 50
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/…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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