473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Date methods from recordset

I use ASP/Javascript. I pull a date from a recordset field like this.

var theDate = new Date()
theDate = rs.Fields.Item("date").value

Now I want to apply the method toLocaleString(). There are 2 things I can
think of

1) change my code to
var theDate = new Date()
theDate = rs.Fields.Item("date").toLocaleString()

But this gives the error that this method is not supported by that object.

2) Add a string variable

var theDate = new Date()
theDate = rs.Fields.Item("date").value
var strDate = theDate.toLocaleString()

Now I get the error message that theDate is null or not an object.

Any ideas?
Jul 23 '05 #1
3 2594
John Kenickney wrote:
I use ASP/Javascript. I pull a date from a recordset field like this.

var theDate = new Date()
So 'theDate' contains the date of midnight on the morning of the
current date according to the user's computer (which may be set
incorrectly and almost certainly not accurately)
theDate = rs.Fields.Item("date").value
What does 'rs.Fields.Item("date").value' return? If it's a
string, you just turned theDate into a string and it's not a date
object any more.

Now I want to apply the method toLocaleString(). There are 2 things I can
think of [...]

Neither of which work (but you knew that). If you want to create
a date for a specific date (say 3 January 2004), use:

var theDate = new Date(2004,0,3);
alert(theDate);

Which, for someone living in Japan, may return something like:

Sat Jan 03 2004 00:00:00 GMT+1000

Depending on your OS, browser, settings, etc. If you want a
decent output format, you must do it yourself, e.g. for an
ISO8601 date generated according to the users' local settings:

<script type="text/javascript">
function addZero(a) {
return (a < 10)? a = '0'+a : a;
}

var theDate = new Date('2004','0','3');
var year = theDate.getFullYear();
var month = +theDate.getMonth()+1;
var daydate = theDate.getDate();
alert(year
+ '-' + addZero(month)
+ '-' + addZero(daydate));
</script>

Note that months Jan to Dec are numbered 0 to 11 respectively.
The addZero() function just adds a leading zero to single digit
months or days. Some also recommend using getYear(), but it has
it's own issues. Read below.
Any ideas?


Read Dr. J's stuff here:

<URL:http://www.merlyn.demon.co.uk/js-dates.htm>
--
Rob
Jul 23 '05 #2

"RobG" <rg***@iinet.net.auau> schreef in bericht
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
John Kenickney wrote:
I use ASP/Javascript. I pull a date from a recordset field like this.

var theDate = new Date()


So 'theDate' contains the date of midnight on the morning of the
current date according to the user's computer (which may be set
incorrectly and almost certainly not accurately)
theDate = rs.Fields.Item("date").value


What does 'rs.Fields.Item("date").value' return? If it's a
string, you just turned theDate into a string and it's not a date
object any more.

Now I want to apply the method toLocaleString(). There are 2 things I can think of

[...]

Neither of which work (but you knew that). If you want to create
a date for a specific date (say 3 January 2004), use:

var theDate = new Date(2004,0,3);
alert(theDate);

Which, for someone living in Japan, may return something like:

Sat Jan 03 2004 00:00:00 GMT+1000

Depending on your OS, browser, settings, etc. If you want a
decent output format, you must do it yourself, e.g. for an
ISO8601 date generated according to the users' local settings:

<script type="text/javascript">
function addZero(a) {
return (a < 10)? a = '0'+a : a;
}

var theDate = new Date('2004','0','3');
var year = theDate.getFullYear();
var month = +theDate.getMonth()+1;
var daydate = theDate.getDate();
alert(year
+ '-' + addZero(month)
+ '-' + addZero(daydate));
</script>

Note that months Jan to Dec are numbered 0 to 11 respectively.
The addZero() function just adds a leading zero to single digit
months or days. Some also recommend using getYear(), but it has
it's own issues. Read below.
Any ideas?


Read Dr. J's stuff here:

<URL:http://www.merlyn.demon.co.uk/js-dates.htm>

Thanks for your reply. I must deal however with the info in the recordset so
I cannot declare a date with the new Date(some date) function. I think I
must downsize my problem how to get a date object from my recordset. Server
side is ASP and I use an MS access database which I approach with SQL.

Maybe I'm in the wrong place here? :-)
Jul 23 '05 #3
JRS: In article <41d9f6c6$0$31857$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 4 Jan 2005 11:47:42, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auau> posted :
John Kenickney wrote:
I use ASP/Javascript. I pull a date from a recordset field like this.
You should have read the newsgroup FAQ, carefully, before posting.
var theDate = new Date()


So 'theDate' contains the date of midnight on the morning of the
current date according to the user's computer (which may be set
incorrectly and almost certainly not accurately)


For me, and IIRC ECMA-262, it will contain the current instant.
Midnight does not occur on a morning; it is between p.m. and a.m. in the
American dialect, and elsewhere is 00:00 of one day and 24:00 of the
previous day.
theDate = rs.Fields.Item("date").value
Variable theDate was previously set to a Date Object, and it is now set
to (probably) a string. So (a) it was a waste of time setting it at
all; (b) if a date object, but not the current instant, were really
needed, then it is better to use new Date(0), for two reasons.

Now I want to apply the method toLocaleString().


You no longer have a Date Object; you have a String which may look like
a date.

IMHO, toLocaleString cannot normally be used for showing dates to
ordinary people on a WWW page; the result will confuse many of them.

One must construct a string that everyone will understand.

The machines in our (British) Public Library are, or at least were,
configured to American format and used mainly by Koreans.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sylvian Tam | last post by:
Hi all, I am using the File System Object to get a list of image through a specified local path : Dim fso, ffolder, ffile, fc, fproperity, strOut, strPic Set fso =...
3
by: imani_technology_spam | last post by:
I know you can use the min function to get the first date within a recordset. However, is there a way to get the second date in a recordset? In other words, is there a way to get "min(date) + 1"...
4
by: keithsimpson3973 | last post by:
Please forgive me for being so stupid. I have searched this site and many others for what should be a simple thing. I have a vb 6 form with a textbox that I input a date into. I can't set the format...
1
by: Jan Paul van de Berg | last post by:
How do I handle date methods like getDate() on values I get from a recordset? Example: rs.Source= "Select SomeDateField From SomeTable" .... 1)...
6
by: teenagelcruise | last post by:
Hi, I have a question,i need to do a task which is when client enter the topupdate and topupamount,the expected expired date will appear on the table,can anyone help me since i have spend 2 weeks...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
5
by: Greg (codepug | last post by:
I have a table that contains a field called RDATE (reminder date). Dates are optionally entered to remind a user of an upcoming event. I have a reminder button that launches a popup form, and a...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
19
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.