Set Post active by current date |
[eluser]TWP Marketing[/eluser]
Zimoon, your if statement will ALWAYS execute the where() statement. Change to a comparision operator (==) inside the if clause, see below... Code: function getactiveCalender($active = TRUE) { Next: Using the CI function unix_to_human() "Takes a Unix timestamp as input and returns it in a human readable format with this prototype: YYYY-MM-DD HH:MM:SS AM/PM". However, you are comparing that output to the timestamp field type which has format "YYYY-MM-DD" or "YYYY-MM-DD HH:MM:SS". The comparison will very likely fail because the two strings are not exactly the same format. I prefer (your choice, not saying you must do it this way) to use integers for date comparison and only convert to string types for screen display. I store my dates as integer values in the db and convert any user input dates to integer before writing back to a database. Your mileage my vary and there are many other ways to handle this.
[eluser]Zimooon[/eluser]
Allright good idea with the int. But how can i change the current date/time ( f.e. now() or time() ) to int to compare it? I changed end now to int(20). But how to get YYYY.MM.DD hh:mms to an int? when i submit my entry i get f.e. intvalue 604 for a full date and the code to the one you posted above (active == false) but now it display all as INACTIVE.
[eluser]Zimooon[/eluser]
Hey to get you on my current stand : My end is atm int(20). my modelcode is Code: function getactiveCalender($active = TRUE) { This is my create_calender controller: Code: function create_calender() Maybe it is a problem to set the entries active/inactive manuall at start? ATM all my entries are displayed. But all are set active = 1 in my database so it seems to be normal. How would you set the end? int(20) is ok? Whats wrong with the model code that it don't write active to 0 when the time expired? best regards
[eluser]Zimooon[/eluser]
ah and here is my view: Code: <?php if(validation_errors()) { ?> If you can't help me , maybe could you show me how you would do it? (Admin/user write : Start End Content and title. The entry is shown until the current datetime is bigger than end(Date + Time) . F.e. 28.04.2011 15:50 is $end and the current time is 28.04.2011 15:43. At 15:50 the entry goes inactiv.(maybe with active == 0 but don't have to be) How to setup my database for this(espacially for end) and how to format the date for output (dd.mm.YY hh:mm) . Please help me best regards
[eluser]Zimooon[/eluser]
Allright guys, to keep you updated ( nobody reads this post ) : i think the problem is my dateformat. now() gives me a string back f.e. NOW: 1304003142 and my input with my DB (timestamp) gives me something back like 2020-04-03 11:11:11 . They can't be compared Now i changed as some helpfull person mentioned above to int(20) again , but here is the problem : it just saves the 2020 and stops. No Unix timecode as now() . I tried to change it with strtotime() and human_to_unix but without success either it just saved 0 or 0000-00-00 etc or just the normal date . My new code for the model : Code: function getactivePosts($active = FALSE) { Well at least i try
[eluser]Zimooon[/eluser]
i changed now the $nowDate = now(); to $nowDate = unix_to_human(now()); with date as integer(Year saved only by stupid integer ) and tada it just show me the posts who are marked with active == 1 and which are under the current Year(2011). So now gogo change the freakin format of date to string or whatever its called(12312344 stuff like that) to compare it better and get the write active == 0 when date<now! Feels like my diary of fail right here best regards
[eluser]TWP Marketing[/eluser]
Zimooon, you've made a lot of changes and I'm not sure that I've understood all of them. I'm going to reference the PHP manual here: http://www.php.net/manual/en/ I keep a copy of this open in my browser. First, to display an integer time (defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970) use date('d-m-Y H:i',$int_time). This will display as dd-mm-yyyy hh:mms You can adjust the output format as you wish. Read the PHP date format descriptions in the php manual here: http://www.php.net/manual/en/function.date.php $int_time = time(); // this returns the integer current time (Unix time in seconds since midnight, January 1, 1970) ie; 1234567890 You can get some history of unix time here: http://en.wikipedia.org/wiki/Unix_time Second, to convert string time "dd-mm-yyyy hh:mms AM/PM" to integer, you could use this format: Code: ... Read the php manual on strtotime() here: http://us3.php.net/manual/en/function.strtotime.php NEXT: your Controller calls this function: Code: ... So I'm not sure which function you intend to call in the controller. but I think your controller should have these lines: Code: ... As I read your model code, getactiveCalendar() will return ALL calendar records by default. If you pass $active = FALSE from the controller, or you don't pass anything, it will return ONLY IN-active records. IS THIS WHAT YOU WANT TO HAPPEN?
[eluser]Zimooon[/eluser]
Hey , yeah i did a lot and most of all tried a lot. I use atm UNIX Timestamp as INT(20) and it works well. My posts get shown when they are flagged as active(by user manually , to have a controll over the shown articles) and when the by the user posted endtime is bigger then the time now. It really works fine now . Your change vom timestamp to dateformat works well but if possible i want something that changes everything in my view which has a timestamp format(134000 etc you know waht i mean) to a Format like this: dd.mm.YY hh:mm. But i don't think this is any codeigniter question anymore . I want it to implement it into my header so every view will get this. I think about js or stuff maybe someone got something? Thank you for your help guys espacially TWP Marketing. have a nice weekend.
[eluser]TWP Marketing[/eluser]
[quote author="Zimooon" date="1304082998"] ... Your change vom timestamp to dateformat works well but if possible i want something that changes everything in my view which has a timestamp format(134000 etc you know waht i mean) to a Format like this: dd.mm.YY hh:mm. But i don't think this is any codeigniter question anymore . I want it to implement it into my header so every view will get this. ... [/quote] Zimooon, Your welcome. To display integer dates, use the date() function (standard php func) and set the output format as you desire: Code: ... I'm not clear about doing "something in your header". I would do this conversion in the model function which prepares the view data, before it is passed to the view. |
Welcome Guest, Not a member yet? Register Sign In |