![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
question for php/sql wizards
what's the best format for me to save dates in my database. i'm still a newb to a lot of this. for what i am working on, i need to reference back upon dates frequently. what is the best format for me to keep thing sin to make things easier on myself down the line?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Apr 2002
Location: /root/
Posts: 4,997
|
You might as well get used with timestamp since you're just beginning.
You can convert it in any format you like when you need to. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Registered User
Industry Role:
Join Date: Nov 2009
Location: Las Vegas
Posts: 18
|
Y-M-D works for us.
__________________
65% Revenue share with NO Pre-checked Cross-Sales - DirtyHardCash FHGs | Morphing RSS Feed | ICQ 586-006-959
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 3,108
|
AJC,
depends on how the data is entered, do you want to tag rows you insert with current time? Or do you want to set the specific time you want for the row when you create it? Do you plan to do calculations on the date? IE one row's date minus another row's date? Or just "get anything since day XYZ"? According to your post's topic, I imagine you use php to do the actual site?
__________________
"Think about it a little more and you'll agree with me, because you're smart and I'm right." - Charlie Munger |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Oct 2007
Posts: 1,448
|
DATE or DATETIME if you need to store the time as well. Allows for all kinds of good date operations. For example, that two week thing:
SELECT * FROM table_name WHERE date_added >= date_sub(now(), interval 2 week);
__________________
xMarkPro -- Ultimate Blog Network Management Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
While I've got you types in here, I might as well ask another question that has been picking at me. Say I'm loading a large text file into an array, just how many elements can an array handle? If I need to load 100,000 lines in, is this going to cause my script to shit the bed, or is that a reasonable number for a single array to handle? Say the text file is upwards of 20mb, like a large datafeed or CSV...
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Confirmed User
Industry Role:
Join Date: Oct 2007
Posts: 1,448
|
Quote:
__________________
xMarkPro -- Ultimate Blog Network Management Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more! |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
What I was aiming for was loading the file into an array and then looping through the array and entering all the values into the database, parsing data out of each line in the text and then putting it into the database in the specified columns for each item. Hitting Google now, and looking at BULK INSERT for importing to SQL. The format of the lines I'm inserting isn't that of a typical CSV, there's several values delimited by different characters. Like one value sperated from the next by a period, then that one sperated from the next by a comma, and then by a space, yadda yadda. So I guess I would have to modify the text file beforehand, and the BULK INSERT? |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Industry Role:
Join Date: Oct 2007
Posts: 1,448
|
Yep, but it's best to do it line-by-line, instead loading the entire file into memory at once. Create mySQL table,then for example:
Code:
$file = fopen('myfile.txt', 'r'); while ($line = fgets($file)) { // Parse data, and insert into mySQL table } fclose($file);
__________________
xMarkPro -- Ultimate Blog Network Management Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 3,108
|
You seem to be in good hands with kiopa....
__________________
"Think about it a little more and you'll agree with me, because you're smart and I'm right." - Charlie Munger |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
As for what format you choose. I MUCH prefer a timestamp over datetime (timestamp is a ten char numerical time value. and date time is like YYYY-MM-DD). I actually loathe datetime for whatever reason. Probably because I always feel it's better to have my hard data in the database be as raw as possible and convert it when parsing it to nicer values once it hits the page.
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
I think the DATE data type best covers what I need to do for now. I have an input list with my date values in MM/DD/YYYY format though. Am I wrong in assuming I have to have my DATE date entries in YYYY-DD-MM format? Or is there a way I can set the column to accept that format of DATE value? Can I convert this quickly on the fly as I enter the values into my table? Or do I have to strip all the day/month/year values out with regex and piece it back together as variables to enter it in the proper date format?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
bump for that ^^^^^^ question
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Confirmed User
Industry Role:
Join Date: Oct 2007
Posts: 1,448
|
Yep. Strip it out, piece it back together.
__________________
xMarkPro -- Ultimate Blog Network Management Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more! |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Ok, I just used a regular expression this morning and got it done. I just wanted to be sure there wasn't a more efficient way to go about it. It wouldn't be the first time I spent an hour referencing, playing around, and writing out all this code; only to find out I could have accomplished the exact same thing with 1 line.
![]() Thanks again for the tips. Appreciated. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 | |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
In SSH or terminal if you can; Quote:
This was for a database of all the postal zip codes in the United States . PHP is way too slow to load databases. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
Confirmed User
Industry Role:
Join Date: May 2005
Posts: 180
|
datetime? depend how you are wanting to use it.... but most often i use datetime
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 | ||
Confirmed User
Industry Role:
Join Date: Sep 2006
Location: Netherlands
Posts: 217
|
Quote:
![]() With regards to the date splitting, using a regexp is ok - however I think just using explode() will/can be quicker. Especially for something this trivial, it doesn't really require a regexp.
__________________
Dido ADAMO Advertising - Your ULTIMATE traffic partner! If you need traffic or have traffic, we'd love to help you make the best out of it! ICQ:24209500 - Skype:diederikvanschaik |
||
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
Code:
$oldDate = "1/12/2011"; list ($day, $month, $year) = explode("/", $oldDate); $newDate = "$year-$day-$month"; ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 | |
Confirmed User
Join Date: Oct 2007
Location: Netherlands
Posts: 415
|
Quote:
so it should be Code:
$oldDate = "1/12/2011"; list ($day, $month, $year) = explode("/", $oldDate); $newDate = "$year-$month-$day"; |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#26 |
Confirmed User
Join Date: Oct 2007
Location: Netherlands
Posts: 415
|
You can do it in mysql directly btw using STR_TO_DATE()
Code:
INSERT INTO ... ( ... ) VALUES ( ... , STR_TO_DATE('1/12/2011', '%e/%m/%Y') , ... ) |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 | |
Registered User
Industry Role:
Join Date: Dec 2010
Location: Close to internet
Posts: 58
|
Quote:
even if you can ofcus, why reinventing the wheel ? ![]() if you feel unsure about the functions, simple queries against mysql as example: mysql> SELECT STR_TO_DATE('1/12/2011', '%e/%m/%Y'); +--------------------------------------+ | STR_TO_DATE('1/12/2011', '%e/%m/%Y') | +--------------------------------------+ | 2011-12-01 | +--------------------------------------+ 1 row in set (0.00 sec) Then you always can see how things will look like and you will learn a lot more about mysql functions.
__________________
Just because I know a lot of things, dont mean I know everything ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 |
Confirmed User
Industry Role:
Join Date: Oct 2009
Location: UK
Posts: 1,865
|
We always store php timestamp to the database, can then display it how you want using php date function
__________________
Affiliate Manager |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#30 | |
Registered User
Industry Role:
Join Date: Dec 2010
Location: Close to internet
Posts: 58
|
Quote:
Down the line, i mean ;)
__________________
Just because I know a lot of things, dont mean I know everything ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#31 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#32 | |
(felis madjewicus)
Industry Role:
Join Date: Jul 2006
Location: In Mom & Dad's Basement
Posts: 20,368
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#33 | |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
Quote:
Got root? bash cron a bash script to do this? I have never done this but I found this as a protype ... Code:
#!/bin/bash P=password D=database U=username mysql -u$U -p$P <<< 'alter database '$D' default character set utf8;' mysql -u$U -p$P -D$D <<< 'show tables;' | while read x; do mysql -u$U -p$P\ -D$D <<< 'alter table '$x' convert to character set utf8;'; done |
|
![]() |
![]() ![]() ![]() ![]() ![]() |