PDA

View Full Version : formatting isofulldatetime to ddmmyy



meenakshi
05-16-2008, 06:01 AM
hi
i m using ms access database to access the records through javascript and html
the problem i m facing is that when i get the date from record it shows me in isofulldatetime format i.e.Wed Dec 10 00:00:00 UTC+0530 2008 where as i want to have it look like 10/12/2008
i have been trying to do a lot of combinations but it always gives me errors
pls help

var vdat=rs("ddate");

and when i try to show vdat it shows the full isodatetime format but when i try to do
var vdat=rs("ddate").dateFormat();
or
var vdat=rs("ddate").format();
or
var vdat=rs("ddate").format("dd/mm/yy");

it shows me error
any clues what i should do to get this right
thanks
anand

meenakshi
05-16-2008, 06:52 AM
can anyone help pls?

jscheuer1
05-16-2008, 08:58 AM
I'm not clear on what you mean. If you were to have this value:

Wed Dec 10 00:00:00 UTC+0530 2008

(which incidentally is actually the 9th in all points west of its time zone locale, including Greenwich due to the UTC value, which could be stripped if desired) in a variable, you could feed it to the Date() method and then extract whatever you need from the object created, ex:


var dateData='Wed Dec 10 00:00:00 UTC+0530 2008';
var dt=new Date(dateData);
var d,m,y;
d=dt.getDate().toString(10);
d=d.length==1? '0'+d : d;
m=(dt.getMonth()+1).toString(10);
m=m.length==1? '0'+m : m;
y=dt.getFullYear();
alert(d + '/' + m + '/' +y);

Or stripping the UTC component:


var dateData='Wed May 9 00:00:00 UTC+0530 2008';
var dt=new Date(dateData.replace(/UTC[^\x20]*/,''));
var d,m,y;
d=dt.getDate().toString(10);
d=d.length==1? '0'+d : d;
m=(dt.getMonth()+1).toString(10);
m=m.length==1? '0'+m : m;
y=dt.getFullYear();
alert(d + '/' + m + '/' +y);

However, this is all client side javascript, which might not be available. And, as I said, if the UTC component is not stripped, depending upon the locale of the user, the precise day of the month, and hence the date (dd or d part) might be +/- 1.

meenakshi
05-16-2008, 09:09 AM
hi john
thanks for ur help but what i was is little different
i have tried what u have written above it holds true for a new current date
but i have a access table from which i take the date value and that variable shows me the date in utc format but i want to convert that date stored in that variable into dd/mm/yy format
that is where the problem arises
it does not convert and shows the problem
thanks
anand

jscheuer1
05-16-2008, 09:20 AM
It also holds true for the date string you supplied. It's just a question of what format the date is in, and if you can get that to the Date method as a string value it recognises. I don't know anything about that part because you have given no indication by which I can determine what server side language you are using. What server side language are you using?

As this is in regard to a data base, you should be able to handle the conversion server side, so you should be asking in a different forum perhaps - One that deals with the server side language that you are using, not the javascript forum.

meenakshi
05-16-2008, 09:29 AM
no i m using only client side javascript to be used on single system
how should i paste the code i mean it is a big code for you to see what i have written
what should i prefix it to show itt in a box ?

jscheuer1
05-16-2008, 09:45 AM
All I need to know is how you get:

Wed Dec 10 00:00:00 UTC+0530 2008

Like - say you did:

alert(some_function())

if that would alert the string Wed Dec 10 00:00:00 UTC+0530 2008 or whatever the date actually is/was in that format, we could work directly from that function.

Now, I setup my example code in my first post in this thread to fire an alert. However, we could just about as easily populate a text input or division with its output.

To show code blocks in a post, use:



Your code here


around it.

meenakshi
05-16-2008, 10:14 AM
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script language="JavaScript">

function getDBFile()
{
var dbfile = location.href;
var idx=location.href.indexOf('pendingpcs.htm');
dbfile= dbfile.substr(0, idx) + "DB.mdb" ;
return dbfile.substr(8);
}

function getSearchResults()
{
try
{
var para = document.getElementById("txtSearchPara").value;
var dbfile = getDBFile();
var cn = new ActiveXObject("ADODB.Connection");

var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+ dbfile+ ";Persist Security Info=False";
cn.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");

var SQL = "select * from notreceived where " +
"asno like '%" + para + "%' or " +
"ddate like '%" + para + "%' or " +
"nam1 like '%" + para + "%' or " +
"mobile like '%" + para + "%' order by ddate, asno ,nam1 ";


rs = cn.Execute(SQL);
var resultString = "<table style = 'position: relative; width: 100%; height: 100%;' border = 1>";
resultString = resultString + "<tr> " +
"<td><b>S.No.</b></td>" +
"<td><b>Delivery Date</b></td>" +
"<td><b>Alteration Number</b></td>" +
"<td><b>Customer Name</b></td>" +
"<td><b>Mobile</b></td>" +
"<td><b>Details</b></td>" +
"<td><b>Remarks</b></td>" +
"<td><b>Pcs</b></td>" +
"</tr>" ;

var vdat=rs("ddate");
var sno=0;

while (!rs.EOF )
{

sno=sno+1;
resultString = resultString + "<tr> " +
"<td><b>" + sno + "</td>" +
"<td><b>" + vdat + "</td>" +
"<td><b>" + rs("asno") + "</td>" +
"<td>" + rs("nam1")+ + "</td>" +
"<td>" + rs("mobile") + "</td>" +
"<td>" + rs("desc1") + "</td>" +
"<td>" + rs("remarks") + "</td>" +
"<td>" + rs("pcs1") + "</td>" +

"</tr>" ;
rs.MoveNext();
}
resultString = resultString + "</table>";
rs.Close();
cn.Close();
document.getElementById("SearchResultPanel").innerHTML = resultString;

}
catch (e)
{
alert ("getSearchResults() : " + e);
}
}
</script>
</head>
<body bgcolor="#FF9520" text="#FFFFFF" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<div z-index: 1" id="MainPage">
<table>
<tr style = "height:100">
<td>
<p align="center"><font size="7" face="Times New Roman">Alterations
Data(Pending Pieces)</font></td>
</tr>

<tr>
<td>
<table>


<tr>
<td>
<table>
<tr>
<td>
Search <input type="text" name="txtSearchPara" tabindex="19" onblur = "getSearchResults();" size="20">
</td>
</tr>
<tr>
<td>
<SPAN id= "SearchResultPanel" > </SPAN>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>

jscheuer1
05-16-2008, 01:54 PM
Sorry to take so many hours, I'm in UTC-0500. I had to get to bed. Now I'm up and fresh. It looks like what I need from your code is:


var vdat=rs("ddate");

As long as rs("ddate") returns an isofulldatetime string, we can do:


var vdat = new Date(rs("ddate"));
vdat.d = vdat.getDate().toString(10);
vdat.d = vdat.d.length==1? '0'+vdat.d : vdat.d;
vdat.m = (vdat.getMonth()+1).toString(10);
vdat.m = vdat.m.length==1? '0'+vdat.m : vdat.m;
vdat.y = vdat.getFullYear();
vdat = vdat.d + '/' + vdat.m + '/' + vdat.y;

Unless you need to strip the UTC component, which as long as you and your records are in and pertaining to (or at least written for) the same time zone, you do not. If you do, or need to convert it to another UTC zone, let me know.

meenakshi
06-30-2008, 09:49 AM
hi
wow thanks a lot
it is working and ur really nice to have taken soo much time to solve this poblem
smile always
thanks a lot once again
:)
anand

meenakshi
06-30-2008, 09:53 AM
hi ur a genius
:)
may u have a smiling day every day:)
anand