Solved

date formats

Posted on 2004-03-22
11
326 Views
Last Modified: 2012-06-21
Hello

I am trying to standardize how dates are stored on my site.

In one place they appear as:
3/13/2004
3/14/2004
3/21/2004

etc...

and another they appear as:
1079551798
1079334828
1079368763

how do I convert the 1st few dates into the 2nd format.

Thanks




0
Comment
Question by:CookieMonster9999
11 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 10653816
Please maintain you old questions before continuing:

1 03/22/2004 500 date formats  Open Active Server Pages (ASP)
2 03/21/2004 500 music files with different bit rates  Open Web Development
3 03/18/2004 250 uppercase vs. lowercase  Open Active Server Pages (ASP)
4 03/15/2004 500 batch mp3 preview making  Open Web Development
8 02/13/2004 500 Locked out of files  Open Windows XP

Please let me know if you need assistance.
0
 
LVL 4

Expert Comment

by:RedLava
ID: 10653868
Hi CookieMonster9999,

I guess that the 2nd format is a serial date format.

The following code converts standard date to serial date:

  <% DateSerial = Date - CDate("January 1, 1900") + 1 %>

RedLava
0
 

Author Comment

by:CookieMonster9999
ID: 10654906
hm... that doesn't seem to be it.

php is inserting time() into the database...

does time include both date and time in php?
0
 
LVL 4

Expert Comment

by:RedLava
ID: 10654938
PHP??
If the database is just storing time then how are you displaying the dates?
now() will store both date and time where as date stores just the date.

The code to use to solve your problem doesn't interface with the database it acts on the date variable.

Place your date from the first output in the 'date' area of the code.

e.g.

  <% NewOutput = OldOutput - CDate("January 1, 1900") + 1 %>

RedLava
0
 

Author Comment

by:CookieMonster9999
ID: 10654965
I tried the code that you posted but it results in entries like this:

38033
38040
38040
38054
38054


which don't seem to match php entries which look like this:

1079551798
1079334828
1079368763



the php entries are coming from the phpbb script which reads:

$sql = "INSERT INTO " . USERS_TABLE . "      (user_id, username, user_regdate, user_password)
VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $new_password) . "')
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:CookieMonster9999
ID: 10655018
I have since discovered that phpbb is using the UNIX timestamp which measures the number of seconds since 1st January 1970.

0
 
LVL 4

Expert Comment

by:RedLava
ID: 10655036
Is this a PHP or ASP question?
0
 

Author Comment

by:CookieMonster9999
ID: 10655049
I'm trying to convert a date and time like 3/22/2004 11:24:00 PM into the phptimestamp format for time which is counting the number of seconds from Jan 1st 1970 until that moment.

I am coding this in ASP
0
 

Author Comment

by:CookieMonster9999
ID: 10655083
0
 

Author Comment

by:CookieMonster9999
ID: 10655158

For anyboyd else that is interested- to get the UNIX timestamp of a current date and time in VBscript:


DateDiff("s", "01/01/1970 00:00:00", now())
0
 
LVL 2

Accepted Solution

by:
hb21l6 earned 500 total points
ID: 10657946
unix time fields are stored as long int strings e.g. 1065103487. This is the same as 02/10/2003 14:04:47. so how is it worked out? very simply, the unix time divided by seconds in a day then add the difference from Microsofts startdate.. unix time starts from the 1 jan 1970 and is counted in seconds. there is also something similar for Microsoft. theres starts at 1 jan 1900. the difference between then in seconds is 25569. seconds in a day is 86400. so the formula looks like this MSseconds = ((unixseconds/86400)+25569).. if that makes sense?


example::


<html>


<b>UNIX TIME CONVERTER<br>
</b>
<small>
This field is a
standard UNIX time field; that is, the time is stored as
the number of seconds since January 1, 1970.
</small>

<hr>

<form name="frm1" method="post" action="#">

<input type="text" name="unixvalue">

<input type="submit" value="convert">
<input type="hidden" name="pageaction" value="nextpage">


e.g. 1065103487 or 1065109172

</form>


<hr>


<%

if request("pageaction") = "nextpage" then

unixvalue = request("unixvalue")

response.write "unix date was " & unixvalue & " and now is... <br><br>"

                ' here is the function to handle the conversion
propertime = ((unixvalue/86400)+25569)



response.write "<br>1: " &  FormatDateTime(propertime, 1)
response.write "<br>2: " &  FormatDateTime(propertime, 2)
response.write "<br>3: " &  FormatDateTime(propertime, 3)
response.write "<br>4: " &  FormatDateTime(propertime, 4)
response.write "<br>5: " &  FormatDateTime(propertime, 0)

response.write  strFormTime


end if
%>

I posted this a while back on bantrax.


any probs let me know!!
hb

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

22 Experts available now in Live!

Get 1:1 Help Now