Solved

Getting utc date into an asp variable withon an asp acript

Posted on 2008-06-10
7
433 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now