Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

date formats

Posted on 2004-03-22
11
Medium Priority
?
337 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
[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
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
Industry Leaders: 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!

 
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
 

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: 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 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/…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

609 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