Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird request.... date() into TIMESTMP

Status
Not open for further replies.

youradds

Programmer
Joined
Jun 27, 2001
Messages
817
Location
GB
Hi. I know this is a bit of a weird request, which may be why I couldn't find anything on Google. Basically, I need to change a formatted date (dd/mm/yyyy) into a UNIX TimeStmp.

Does anyone know how I could go about this?

Cheers

Andy
 
Weird....its not working (keeps returning -1)...code is;

// work out if the due date has passed...
$duedate = $row[DueDate];
$duedate = strtotime("d-m-Y");

$todaysdate = date("d-m-Y");
$todaysdate = strtotime("d-m-Y");

echo "$duedate and $todaysdate";

Fomr some reason, that prints out:;

-1 and -1

Anyone got any ideas? :-/

Cheers

Andy
 
I now have;

// work out if the due date has passed...
$duedate = $row[DueDate];
$duedate = strtotime($duedate);
$todaysdate = date("Y-m-d");
$todaysdate = strtotime($todaysdate);

echo &quot;$duedate < $todaysdate <BR>&quot;;
if ($duedate > $todaysdate) { echo &quot;match...passed $row[DueDate]<BR>&quot;; }

Thats giving stuff like;


1919113200 < 1058828400
match...passed 25-05-2004
1811286000 < 1058828400
match...passed 21-12-2003
1782428400 < 1058828400
match...passed 21-01-2003
1782342000 < 1058828400
match...passed 21-01-2002
1795478400 < 1058828400
match...passed 21-06-2003

Why is it matcihn all of them? :-/

Cheers

Andy
 
If you're wondering why a date earlier than today is matching as greater than, it's because of the &quot;gotcha&quot; I mentioned in my first post in this thread.

This code snip:

<?php
print date ('Y-m-d', strtotime('2003-07-22'));
print '<br>';
print date ('Y-m-d', strtotime('22-07-2003'));
?>

outputs:

2003-07-22
2027-12-24



Want the best answers? Ask the best questions: TANSTAAFL!!
 
MMm...this is doing my head in :| The code I have is;

// work out if the due date has passed...
$due_date = $row[DueDate];
$due_date = explode(&quot;-&quot;,$due_date);
$duedate = strtotime($due_date[2]-$due_date[1]-$due_date[0]);
$todaysdate = date('Y-m-d');
$todaysdate = strtotime($todaysdate);

echo &quot;Dates: $due_date[2]-$due_date[1]-$due_date[0] ($duedate) and $todaysdate<BR>&quot;;
//echo &quot;$duedate < $todaysdate <BR>&quot;;
if ($duedate > $todaysdate) { echo &quot;match...passed $row[DueDate]<BR>&quot;; }

This returns stuff like;

Dates: 2004-05-25 (1058987640) and 1058914800
match...passed 25-05-2004
Dates: 2003-12-21 (1058987400) and 1058914800
match...passed 21-12-2003
Dates: 2003-01-21 (1058988060) and 1058914800
match...passed 21-01-2003
Dates: 2002-01-21 (1058988000) and 1058914800
match...passed 21-01-2002
Dates: 2003-06-21 (1058987760) and 1058914800
match...passed 21-06-2003

What I need is for a 'passed' value to be shown ONLY if the DueDate has been passed by the current date. Does anyone have any similar working code I could look at/use?

Cheers

Andy
 
Man, this date stuff is really getting on my nerves!

$wedding_date = &quot;21-11-2003&quot;;
$time = strtotime($wedding_date);
echo &quot;Today: &quot; . strftime( &quot;%d-%m-%Y&quot;,time()) . &quot;<BR>&quot;;
echo &quot;TimeStmp: $time<BR>&quot;;
echo &quot;Today2 : &quot; . $todays_date = strftime( &quot;%d-%m-%Y&quot;,$time) . &quot;<BR>&quot;;

...produces;

Today: 23-07-2003
TimeStmp: 1808694000
Today2 : 26-04-2027

Anyone got any idea why its coming up as 2027? I'm totally stumped :|

TIA

Andy
 
You are running afoul of the &quot;gotcha&quot; I mentioned in my original post.

I will be explicit:

strtotime() has problems with dates of the format &quot;DD-MM-YYYY&quot; and &quot;MM-DD-YYYY&quot;. If you want good behavior out of strtotime() when using number-only date formats, pass it dates of the format &quot;YYYY-MM-DD&quot;.

The following code:
Code:
<?php
//Interpreting number-only date formats for June 6, 2003
print date ('Y-m-d', strtotime('01-06-2003'));  //Europe
print '<br>';
print date ('Y-m-d', strtotime('06-01-2003'));  //U.S.
print '<br>';
print date ('Y-m-d', strtotime('2003-06-01'));
?>

Outputs the following:
2006-11-24
2011-06-26
2003-06-01

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Aaaah...I see. This seems to be working great...thanks :)

$got_date = explode(&quot;-&quot;,&quot;21-11-2003&quot;);
$wedding_date = strtotime(&quot;$got_date[2]-$got_date[1]-$got_date[0]&quot;);
$todays_date = strftime( &quot;%d-%m-%Y&quot;,$wedding_date);

$_days1 = strftime( &quot;%d-%m-%Y&quot;,DateAdd(&quot;d&quot; ,1, $wedding_date));
$_days7 = strftime( &quot;%d-%m-%Y&quot;,DateAdd(&quot;d&quot; ,7, $wedding_date));
$_days14 = strftime( &quot;%d-%m-%Y&quot;,DateAdd(&quot;d&quot; ,14, $wedding_date));
$_days30 = strftime( &quot;%d-%m-%Y&quot;,DateAdd(&quot;d&quot; ,30, $wedding_date));
$_days90 = strftime( &quot;%d-%m-%Y&quot;,DateAdd(&quot;d&quot; ,90, $wedding_date));
$_days180 = strftime( &quot;%d-%m-%Y&quot;,DateAdd(&quot;d&quot; ,180,$wedding_date));

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top