Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Convert User Entered Date And Time To Unix Timestamp Before Inserting To Database


How do you convert a user inputted date to a unix timestamp before
insterting it into your database? I have a form, with a textfield for
a date that the user inputs in the format mm-dd-yyyy and three dropdow
boxes for hours, minutes, and AM/PM. All of these need to be considered
together and converted to one Unix Timestamp and then inserted to the
MYSQL date field. The type of field is INT (11) so that I can instead
of the standard 0000-00-00 format of MYSQL so that I can do better
calculations and queries.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Convert Unix Timestamp To Date('Y-m-d H:i:s')?
How do you convert a unix timestamp to date('Y-m-d H:i:s')?

SQL Date/time Or Unix Timestamp?
Generally when developing applications I use unix timestamps as the method of storing dates in a sql database. However, I was wondering if I should use the standard date-time used by the database. The question then arises: continue using PHP to manipulate the dates, or allow the sql server to take over.

Can anyone provide any reasons to use sql date-time rather than unix timestamps?

Getting Time Of Day From Unix Timestamp
I'm working on my CMS, Thacmus, and I've run into one helluva snag (well, nothing big). I'm working on adding the time of day to my date field, since I've procrastinated on that, but I'm having trouble trying to get the time of day from the timestamp without it interfering with the day. I've managed to supress this with the two asterik'd Here's the code for the two fields, date, and time: Code:

UNIX Timestamp To Date
I looked in the forums little and in the php manual but I didn't find what I wanted. I want to know how I could change a unix timestamp into a normal date such as MMDDYYYY.

Date To Unix Timestamp
I am getting a date and time from a user. The send in a date with the format dd-mm-yyyy and a time with format hh:mm and then send in whether it is am or pm. now i split the date and time, then try to figure out the hour using: Code:

Convert Date To Timestamp
Which one of the php functions will convert a date into a timestamp. I'm
looking at the date/time functions on php.net, but they all seem to work
the other way.

Getting Date (timestamp) As Time Value?
I'd like to read out a date from the a DB, but as time var. By default
I seem to get it as a string.

E.g.

while(odbc_fetch_row($result))
{
$tt= odbc_result($result,2);
echo date("d.m.Y", $tt).", ".odbc_result($result,6) . " <br>";

Date/time To Timestamp
Is there any built-in PHP function that can turn something like "2007-04-18 18:00:00" into a timestamp?

Delimiting Timestamp Queries To Show Only Date, No Time
I can't find anything on google or even searching the forums that comes remotely close to being understandable by me. I have a MySQL timestamp(current timestamp) I'm using to date every entry. HOWEVER, I can't figure out how to get rid of the time portion and only display the date.

Inserting Date & Time
I am using now(), but I'd like to use strftime("%d. %B %Y %R"). I can't for the life of me figure out how to use strftime("%d. %B %Y %R") in the code below without it failing.

The other issue is that both now() and strftime("%d. %B %Y %R") return 9/27 as the date. But it's 9/28.  How can get it to return the correct date? I thought the setlocale would address this. Code:

Inserting Current Time/date.
I am trying to insert the current date/time into a MySQL table field when a record is inserted, however i cannot get it to work. My PHP is basically like this:-

$sql = "INSERT INTO Table (ref,title,first,surname,telephone,mobile,ila,ila_date,status)
VALUES ('$ref','$title','$first','$surname','$telephone','$mobile','$ila','NOW()','$status')";

The field called "ila_date" is where i want to add the current date/time. Ive read about the NOW() function, but i think im useing it incorrectly. My MySQL table column "ila_date" is of type timestamp(14).

How Do U Convert Date Time Stamp For RSS Feed
Need help in converting my sql date time stamp in RSS compatiable. Currently my date time is in this format 2005-12-21 15:34:14

Converting An SQL TIMESTAMP Into Unix Timestamp
I look over the docs on MySQL, and I'm assuming MS SQL will be quite similar. I am trying to decide how best to pull this off. I am anticipating a need to take the typical SQL TIMESTAMP and convert it to an Unix Timestamp...

Now, as I look at this a TIMESTAMP stores namely a "numerical" format in a 14 Digit String. I'm just wondering if anyone has a suggestion as to how I might split this into the componenets (4d Year/3d Month/2d Day/HH MM SS) so that it could be passed through mktime() (which will give me the unix version).

Actually, I think I may have an approach.. perhaps using the php substr() function..
since it returns a "defined" portion of a string.. if $x was our timestamp, we'd have to pass it through the substr() function a few times, to pull out the pieces we wanted.

Inserting Date Into Database
I have a pretty simple news code that inserts the data, and then is retreaved, with a pretty simple scheme. I have a date column set at timestamp(14), and I'm trying to insert NOW() as the date. I browse with phpmyadmin and all it has is 14 zero's. PHP Code:

Inserting Date In Database
I have form which allows a user to select a date as part of the form.
On submitting i am getting no update to the database and no error message.
To try and test it i created a shorter version which sets up the variables except the date.This gives the same result.ie no update. Code:

Convert Date From A Database Query
I have a simple database for events. I have a column named "date" that I would like to display as "March 8, 2007" on the webpage. What do I need to add to change the date format? Here is my php code:

Inserting A Date Into A Microsoft Access 97 Database
I was wondering if anyone could help me insert a short date into microsoft access 97 using php? i can insert text no problem but i can't seem to be able to insert a date properly. i have been using

//$date = "#" . "$sqlmonth" . "1" . "$cboyear" . "#";

$strSQL = "INSERT INTO tblSupport (tDate) VALUES ($date)";
$result = odbc_exec($connect, $strSQL);

Note: i can insert a date if i hard code it like putting in #01

Datetime Vs Unix Timestamp
I have been making a few minor "programs" using php. In them, I have a lot of date tracking and storing of various types of dates.

A while back I had used phpBB a lot and learned a lot about coding from modifying the forum to my needs. Well, they stored all dates as UNIX timestamps. Now I know that they have the ability to allow users to have their own date formats and be specific to different timezones.

Well, ever since then I have been using timestamps to record and compare any date or time info. I have been running into a lot of problems lately with it though. I cannot do dates before 1970 or after 2070. My dates have been coming out a few hours off also. Now I use various functions to change timezones for users and stuff, but even though I am very sure they are right, my times still come out wrong.

My big question is, does anyone know why they used the timestamp instead of datetime? I figure you can use datetime in the database and then convert/compare it any which way you want with php and sql statements. Are theere pros and cons? Specific reasons? I also know they support other databases than MySQL, is it because they may not have datetime?

Best MySQL Field Type For Unix Timestamp?
What do you recommend as the best type of field for a timestamp in a MySQL
database? I've considered varchar(10) or INT but I'm not sure what is the
best, most efficient, and most reliable field type.

Select Distinct Year From Unix Timestamp
I'm trying to select all distinct years from a unixtimestamp field in
MySQL database. I have a query:

SELECT DISTINCT YEAR(date_field) As theYear FROM table

but it gives me an empty array. What am I doing wrong?

A Few Questions About My Code Consistency And Remembering User Entered Data...
I am relatively new to php and am looking for a couple of pointers on some code that I am writing. I coded a page that seemed like it was ok until I found out about a little thing called "error_reporting(E_ALL)" and then, well, sheesh.....

So... after MANY hours of dancing around I finally came up with something that seems to be ok -- at least it doesn't report any errors anymore and am just wondering if this is how the pros do it or not. ANY constructive criticism or pointers will be greatly appreciated.

What it is is a page with a form on it that has two required fields on it (name and email address), if somebody fills out the form but DOESN'T fill out the two required fields then I want the form to remember the values of the fields that were filled out. Further, I have it doing some error checking on a couple of the other fields ONLY if they are filled out as they are NOT required. All this works as is and it builds the email message, formats it and sends it. Like I mentioned before I am trying to figure out what is "good" code practice and what is not.

Ok. here is the main form page. I know this is quite long -- sorry, but I have actually edited out a bunch of things that are just repetitive.

Date & Time Format In Database.
I'm using MySQL database, the problem is I've setup that user input the Date format in dd/mm/yyyy (example: 14may2007) and Time (example: 12:00pm). How do I convert it to Date & Time format in database format before insert into database? Sorry, noob here.

Insert Server Date / Time Into Database
I currently have the following to insert a variable into a database:

$zip = $db->escape($_POST['zip']);
$db->query("INSERT INTO zip SET zips = '$zip'");

I would like to also add the date & time the submission was made.

Taking Date Of Birth From User And Sending It To A Mysql Database
i have created a form that takes a users date of birth as 3 seperate values $day $month and $year i do not know how to combine these values into a single value called $dob.
I tries using just a singal value to take the date however it did not work, even after I had formated my database.

Convert NOW() Into PHP Timestamp
How do I convert a field entered into a Mysql database using NOW() into
a format that can be manipulated with PHP's strftime() function?



Sort Results By Date/time, Limit 5 Database Entries Of Today &/or Upcoming Days
I'm designing a website for my fraternity and in the database I have entries which contain past events, todays events, and upcoming events.  My problem is that I can not figure out how to sort the query results to display:
 
1) only past events based on the CURRENT DATE
2) only the events which fall on the CURRENT DATE or after, limiting the results to 5 entries
3) all events that fall on CURRENT DATE or afterwards

Example:   
Today is  September 15, 2007

Problem 1) Displaying all events that happened before September 15, 2007
Problem 2) Displaying only 5 results that fall on September 15, 2007 or after
Problem 3) Displaying all events that are happening on or after September 15, 2007

And obviously I would like the CURRENT DATE to change depending on what date it is, currently.

Ok so now I've been very redundant in my explanation of my problem here is the code and a link to what that particular page looks like. Code:

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:

Unix Time Stamp
I have seen a number of people refering to it, and I am wondering what they are talking about?

Unix Time Comparison
I am trying to select records within a day interval. However the comparison of the timestamp seems not to work. uniquied is timestamp. Code:

Unix(?) Time Conversion From DB Entry...
I searched this forum for an answer, and tried a few things (like the date( function, but it didn't work.

This is for PHP3 (yeah, don't ask, I'm pissed about it too).

I am pulling a date from a database entry that uses what looks to be a unix timestamp (1001742756 is an example). This is for a search engine I'm currently ripping apart to suit my own needs. Here's the line of code I need to insert the time into:

echo "&nbsp;Hits In: ".$get_rows[HitsIn]." Hits Out: ".$get_rows[HitsOut]." Last Checked: ".$get_rows[last_check]." Status: ".$get_rows[checker_status]."<br>";

So what I'm trying to do here is pull from the last_check row and format it in a human-readable format.

Unix Time Stamp Question
How do you convert a date like 00/00/00 into a Unix time stamp?

Unix Time And Leap Seconds
I have Red Hat Enterprise Linux 4.

I was just reading up about UTC and leap seconds.

Is it true on my system that the Unix time may skip up or down by one second
at midnight when there is a leap second?

By "Unix time" I mean the integer returned by time() and similar functions.

I'm concerned about the "down" case. Some of the software I've written
assumes monotonically-increasing time.

Changing Unix User Passwords On Website
I'm a new user of PHP and MySQL, already making progress in a very short time and astonished at how totally cool it all is. As always when I learn new stuff I'm jumping in to the deep end--or at least it seems like the deep end to me.

Basically what I want to do is allow people who have the right to log onto the unix machine to be able to logon to my website with thier unix usernames and passwords and then change their passwords on the site. I'm seeing tutorials etc on authentication/tracking, well and good, but it's usually with a database, cookies, flat files, .htpasswd files etc. These I can manage.

What I would like is some advice on how to do that. How do you use PHP to log onto a UNIX system and change the password via a database? What should I look for? Where do I start? I'm not at all averse to figuring out how to tie things together myself, but it would be nice to hear what to do and what not to do from experienced folks who've done it--things to watch out for etc...

Time, Timestamp?
I have a mysql db that contains a timestamp=
20010626114705
When I use getdate() to convert this to the correct date I get:
$today = getdate($tijd);
$month = $today['month'];
$year = $today['year'];
$mday = $today['mday'];
$hours = $today['hours'];
$minutes = $today['minutes'];
$weekday = $today['weekday'];
echo "$weekday $mday $month, $year $hours : $minutes";
= Monday 18 January, 2038 22 : 14

any ideas what is going wrong?

Unix Time Stamp As Float Instead Of Integer?
I just noticed this when I was catching up on old posts:

function getmicrotime(){
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);

$sec should be a Unix timestamp, which is an integer. What is the point
of casting it to a float?

Date & Time Fields To Printed Date/time
How can i take data from date and time field and convert:

2003-02-26 to 26th of Febuary 2003

And: 19:25:00 to 7:25 PM

Dropping The Time From A Timestamp
I am looking to display the date in a field but I can't figure out how to make the timestamp drop the hours:minutes:seconds. My timestamp originally comes in formatted like "2006-01-01 00:00:00" and I wish to have it read "2006-01-01" only. I've tried using the echo (date("Y-m-d",$row_getProject['EndDate']))

but it returns an error that reads:

Notice: A non well formed numeric value encountered in C:htdocsadminEditProjects.php on line 109
1969-12-31

and it adds the date of 1969-12-31 for some reason. Does anyone know how I might be able to solve this issue?

What The Timestamp From Time() Format Is
I am trying to decipher what the unix time below represents. Through my searches, it represents the seconds past from a certain date past. Is that correct??

1063115283

I am writing a script that does something after 10 minutes have passed. would 10 minutes be 10 *60 = 600 ?? Would that have to be the difference?

MySQL, Time() And Usinx Dates Unix Style
I have a field in my DB that saves the date/time as a integer.
I get the time on my server using the time() function.

now, moving away from php and looking at (My)SQL only.
If I use functions like DATE() or NOW(), I don't get a Unix value, (but
rather a formatted date).
So I cannot use those functions to check against my saved value.

How can I run a query that would get, say, 1 hour before the current time?

Timestamp -> A Useful Date
hi, i want to display a formatted version of the next 7 days on a page. I can add so many seconds to a timestamp, but, how do i convert that timestamp into a useful formatted date?

Get Timestamp Of Date
I have a date object which I want to get the timestamp for. The date is 24/8/2007 18:30:00 I simply want to determine what the timestamp is for this date and time so that I can compare it against the current timestamp. The problem is that the timestamp is for the current time, not the date and time that I have specified.
Here is my code:

  $mydate = date("d-m-Y : H:i:s", mktime(18, 30, 0, 8, 24, 2007));
  $datestamp = time($mydate);
  echo 'My date: '.$mydate.'  -  Date stamp: '.$datestamp;

Getting Timestamp To Formatted Date
I have a timestamp field in a Mysql table and have tryed to get it to unix timestamp form and then format it with date() but i've had no luck. Can anyone enlighten me on how to do so?

Date From Form To Timestamp
If I have web form with fields: DAY, MONTH, YEAR, TIME, how can I get
Unix timestamp afther submiting that form.

Mysql Date To Timestamp
I would like to use php to query a database and retrieve a unix timestamp.

The problem is that mysql is storing the data in the date format and not
a timestamp.

I am sure that I can amend my query to format the date returned as a
timestamp without having to do the conversion in php.

Can someone tell me what to put in my db query?

Making A Timestamp From A Date
I have a date in the form: 2003-01-03 15:16:08

I need to make a time stamp from it - any ideas?

Fetch The Date From Timestamp
i have a mysql table with 3 fields

1.id  2.time 3.approved

values

1  1181237691  0
2  1181237703  0
3  1181237711  0

i want to fetch the distinct dates from this timestamp values using select statement.

i want to display like this
1  2007-06-07

second thing i want to update the approved value=1 where these distinct dates are equal to the above timestamps.

A "bad" Unix Timestamp?
I ran into an interesting gotcha with unix timestamps.

I've got a page where the user inputs the date with drop-down boxes
(easy to deal with), that my script sees as (say) $d $m $y, not
necessarily in that order, but you get the idea, nicely formatted with
leading zeroes and so on.

Then I run it through checkdate($m, $d, $y) just to make sure the user
doesn't think there's 31 days in September or whatnot.

That's all fine. Then I think, well, it would be nice if I could tell
the user something like "there's not that may days in $m" and I should
be able to use strtotime() and date() -- but it turns out (and rightly
so) that you can't create a "bad" Unix timestamp.

For instance,

date ("F d Y",strtotime("2004-09-31"));

will return October 01 2004 and fwiw, so will

date ("F d Y",mktime(0,0,0,9,31,2004));

I can write a switch, of course, and there's only 5 cases (30 days
hath September etc., plus February needs to be dealt with). It
intrigues me, though, and I wondered if anyone else had played with it.

MySQL TIMESTAMP Field And PHP's Time() Function
I have a table in MySQL with a field of type TIMESTAMP, whenever i try to insert some value in it using : "INSERT INTO mytable set myfield=" . time();

It gets doubled or tripled i.e. it gets multiplied by some ratio. and when i extract that value and try to format the output with the date() function it shows some day of 2038....
Is there any incompatibility in TIMESTAMP and time() ?

Reading A Log File One Line At A Time Depending On Timestamp
Currently I am attepting to create a stats package for my companies website (yes my life would be 100% stress free if I was allowed to use a standard/commercial stats package ).

So far things are all good, and ive progressed quite far. But ive hit a snag.

At the moment im reading in the WHOLE log file and sorting it into an array and passing the neccesary data to mysql. Easy peasy.

But my boss has pointed out to me that as the site gets more and more traffic the log gets bigger, and if it gets to big the servers memory will overload, and we all know what happens then!

So what I need to do is read in the file one line at a time. and compare the timestamp to the last time the script was run. If the timestamp in the log is less than the last timestamp for when the file was run dont read it. If it is more than defiently read it. Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved