Date Conversion With Mktime?

Jun 11, 2010

I have a date like which comes from database under variable say $logindate; I have to convert this to formatted date with the use of mktime(function)

like: mktime(0,0,0,d, M, Y);

How can I do this conversion,

View 1 Replies


UNIX Mktime To MySQL Date Or Date

A form that sends a starting date and an ending date. I have figured out how to tell the difference between the two and even rip the difference into an array because I need to compare the individual dates against a mySQL database to pull results from a particular date in a series. This is no problem. My problem is that teh mySQL database uses DATE as a field definition and this can not be changed. I managed to pull the date differences using some cleaver mktime stuff but no I do not know how to get this 1072242000 into this 2003-12-24...

Is there a function that reverses the mktime result into a usable date format? I would take anything at this point and I can explode and then array it to get what I want - but there has to be something. Code:

View 5 Replies

Mktime() And Date()

My users submit the date in format mm/dd/yyy via post, and I then want to display in a particular format using the date() and mktime() functions.

//format class dates
$classdate[0] = $_POST['classyear'];
$classdate[1] = $_POST['classmonth'];
$classdate[2] = $_POST['classday'];
$classdate = implode("-",$classdate);
$classdateDisplay= date('F d, Y', mktime(0,0,0,$classdate[1],$classdate[2],$classdate[0]));

echo "debug: $classdate = $classdate<br />";
echo "debug: $classdateDisplay = $classdateDisplay<br />";

When I enter the values 2008/01/01 in the form, $classdate then correctly is displayed as 2008-01-01.

But when I echo $classdateDisplay, it displays "December 3, 2001."

I'm following the formatting as described (here), which is:

int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )

What am I missing here?

View 2 Replies

Date And Mktime()

I am having a prob inserting a timestamp into database. My form passes a manually entered date in this format dd-mm-yy (eg 01-02-06). I then use this code to seperate the date, month and year; PHP Code:

$date = explode("-", $date);
$date = mktime(0,0,0,$date[1],$date[0],$date[2]);

Problem is that the timestamp doesnt seem to change, no matter what date i input, it stores in the database as 8388607.

View 3 Replies

Date Conversions ( Date, Mktime )

I have a date in three pieces dd mm yyyy.
I'm just wondering the best way to convert this for inserting into a
DATETIME field and then back again when displaying it.

I have tried date, strtotime mktime but it keeps inserting a blank
date. i.e. 00:00:00 00:00...

I've been looking through the php manual but I can't seem to get this
Also would I be better off using the UNIX_TIMESTAMP function?

View 3 Replies

Problem With Date() And Mktime()

I have a php mailing list script written by someone i can't remember but its a good script so thanks. The problem is that when I send mail out it does not reach aol or lycos users. Is this because they see this as spamming?

I changed the from bit to a valid email address but it still doesnt work. Does the mail function need any extra parameters to show its not spam if that is the problem.

View 5 Replies

Can't Get The Actual Mktime Date()?

After trying so many times still confusing....Please guide me !

PHP Code:
echo "the expiry date is:".date("d/M/y/,g:i",$mydate)."<br>";

The result is :09/Jun/11 Suppose is : 30/Jun/09

View 2 Replies

Compare Two Date Using Mktime?

I have a string that is submitted via a form and need to check to see if it is within a date range (10/04/09 - 05/06/09). String format is d/m/y. Ive been playing around with the code below but have had no luck. Im not new to php but Ive had next to no experience with date functions. I have also tried using strtotime() but it changes the d/m order around.

$date1 = date("d/m/y", mktime(0, 0, 0, 04, 10, 2009));
$date2 = date("d/m/y", mktime(0, 0, 0, 06, 05, 2009));
$date3 = $_POST['date'];
$parts = explode('/', $date3);


View 2 Replies

Date() And Mktime() Output Mar Instead Of Feb

I'm getting a wierd result using the date function along with mktime. here's my code: echo date('M', mktime(0,0,0,2));Looks simple enough.. For some reason though it outputs 'Mar', but march is the third month. If I switch the 2 with 3 it outputs 'Mar'. All the other months come out correctly, just feb comes out as 'Mar' and I can't figure it out...

View 4 Replies

Date Manipulation - Mktime

I have created 2 pages to query a database. There are 2 bits of date manipulation with which I am having a problem:

Last Week and Last Month - when the user clicks Last week, I need a string produced. If today is 05/05/2007, the string I need produced is "29/04/2007...04/05/2007" which is the last 7 days.

If the user clicks Last Month, I need just the number produced, so if this month is May, I need 4 produced. I have tried all sorts of stuff with mktime, but it just produces rubbish, here is an example of my code:

View 4 Replies

Strange Problem With Mktime And Date

I have a strange problem with mktime and date:

date("D-d-M-Y",mktime(0,0,0,4,1,2001)); returns Sun-01-Apr-2001
date("D-d-M-Y",mktime(0,0,0,4,2,2001)); returns Thu-29-Mar-2001
date("D-d-M-Y",mktime(0,0,0,4,3,2001)); returns Fri-30-Mar-2001
date("D-d-M-Y",mktime(0,0,0,4,4,2001)); returns Sat-31-Mar-2001
date("D-d-M-Y",mktime(0,0,0,4,5,2001)); returns Thu-05-Apr-2001

Can someone explain me?

View 2 Replies

Mktime, Date, And Adding Hours

I want to take the current time and add 8 hours using the following format: PHP Code:

View 5 Replies

Date Calculation Problem W/ Mktime()

I am having a problem with calculating a date. What I am looking to do
is get the date of Sunday of this week, then use mktime() to find out
other days in the past by subtracting days.

In the code below, today is Saturday, October 16, 2004, this week's
Sunday is 2004-10-17. I successfully get that.

But, when I try to subtract 7 days using mktime(), I instead of getting
2004-10-10, I get 1969-12-31.

I have looked through and searched some example via
Google, but I stuck. Any help would be greatly appreciated.


$today = unixtojd();

$this_sunday = $today + (7 - jddayofweek($today)) % 7;
$current_sunday = jdtogregorian($this_sunday);
$this_sundays_parts = explode("/",$current_sunday);
$cur_sunday = $this_sundays_parts[2] . "-" . $this_sundays_parts[0] .
"-" . $this_sundays_parts[1];


$last_sunday = date("Y-m-d", mktime(0, 0, 0,
date($this_sundays_parts[2]), date($this_sundays_parts[0]),

print "This Sunday is " . $cur_sunday . "<BR>";
print "Last Sunday was " . $last_sunday . "<BR>";

View 1 Replies

Date And Mktime Function Usage?

How come its not printing out the right date output. where I am making mistakes. PHP Code:

$tomorrow = mktime(0.0,0, date("m") , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
$nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);

echo "$tomorrow<BR>";
echo "$lastmonth<BR>";
echo "$nextyear<BR>";


View 1 Replies

Insert Date From Mktime Into MySQL?

I want to insert date in format m-d into database. I used this code

$date1=date("m-d",mktime(0,0,0,$month1 ,$day1,1));

The date is inserted as 0000-00-00 in MySQL, and I don't know why.I want to do that to compare that date stored in MySQL with current month and day. How can this be done?

View 2 Replies

Subtract One Date To Another Using Mktime Funtion?

how to subtract one date to another using mktime fn...

View 2 Replies

Mktime Returning Wrong Text Date

I am pulling numerical month data from the DB and converting it to a text format using mktime() and date() functions. PHP Code:

View 7 Replies

How To Convert Time(mktime) To Date(mm/dd/yyyy)

ok i have a birthday form that will save as time using mktime, so when it is saved in mysql, it will show something like 634608000.. how can i convert it to mm/dd/yyyy format so that when it is displayed in html it will be readable..?

View 1 Replies

Is Mktime() Using Date() Daylight Saving Aware?

I've read through a few questions about this here on s.o. and none seem to ask or answer the question very bluntly: $ts_today = mktime( 0, 0, 0, date('m'), date('d'), date('Y') ); is this daylight saving aware? if not, how do i make mktime() daylight saving aware?

View 2 Replies

Pass The Contents From $row[date] Into The Mktime() Function?

New user of PHP here! I'm using it to display entries from my MYSQL database. Image below.

This is the code snippet that displays information from the 'name', 'author' and 'date' columns of my database. I learned this technique from w3schools.

$result = mysql_query("SELECT * FROM levels ORDER BY date DESC");

while($row = mysql_fetch_array($result))
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['author'] . "</td>";
echo "<td align='right'>" . $row['date'] . "</td>";
echo "</tr>";

I would like to use the date() function to format the date differently. But the date() function requires that I convert my time into a timestamp. I know you have to use the mktime() function for this, but I don't know how. how to pass the contents from $row[date] into the mktime() function?

View 4 Replies

Arbitrary Mktime - Doesn't Allow Negative Date Values

I'm prefacing this post by saying that I already know that the unix epoch is 1970 to 2038 and that Windows doesn't allow negative date values. Just so that isn't regurgitated as an answer and I waste more time on this issue. I have a function that takes a user's birthdate and validates it by which I mean it makes sure that they aren't born before 1900 and are at least 18 years old.

function mkBDay($month, $day, $year) {
$month = str_pad($month, 2, "00", STR_PAD_LEFT);
$day = str_pad($day, 2, "00", STR_PAD_LEFT);
if($year <= 10) {
$year = str_pad($year, 4, "2000", STR_PAD_LEFT);
} else {
$year = str_pad($year, 4, "1900", STR_PAD_LEFT);

I've assigned a variable to the mktime call at the end and dumped it during a little testing. What I've seen is that if the year is before 1970 and before 1902 the value is negative. Fine. However if the year is 1900 or 1901 it's false. The inconsistency doesn't make any sense to me and seems arbitrary. Is there a reason that it doesn't like either of those years? Or maybe I wrote my function incorrectly.

View 1 Replies

Convert Date - Times Format To A Timestamp Using Mktime()

I want to use the mktime function to convert date-times in the format 26-Jan-2011 15:21:33 to a timestamp, the date-time is an input from a text box using a javascript datetime picker. How do I make the date-time in that format fit into the parameters of the mktime function.

View 2 Replies

Mktime With A Date Less Than The Year 1969 I Get A Negative Integer?

When I do mktime with a date less than the year 1969 I get a negative integer. That is fine however because when I used date it would get the correct time for say a date in the year 1945. But I just noticed when I do say year 1900 it will just use 0.

View 1 Replies

Numerical Date To Word Date Conversion?

I am using the following to take the following format: mm/dd/yy to show November, 19, 2008 for example:

echo date('F d, Y', strtotime('{$month}/{$day}/{$year}')); IN my db i have the $month, $day, $year stored as an INT. When i add the variables into the date function the out put is wrong, meaning i am getting an incorrect date. The date i have in the system is 2/1/1977 but the output gives December 31, 1969.

View 1 Replies

Mktime - Calculate Date Difference In Week,month Year ?

I am new here and php i want to know how to calculate date difference in php.My date is mktime() formate.

View 2 Replies

Date Conversion Again

I'm using this in my php form:

[$DOB = date('Y-m-d', strtotime($StrDOB));]

Of course, it doesn't work on dates prior to 1970. I am trying to convert a Date of birth from mm/dd/yyyy format to yyyy-mm-dd format (MySQL default) on a WAMP installation. Can anyone point me to a workaround?

View 3 Replies

Copyrights 2005-15, All rights reserved