Note that there are some explanatory texts on larger screens.

plurals
  1. POstring:str for string from database
    primarykey
    data
    text
    <p>I have model with some fields. I want to get string field from mongodb and get substring. I'm trying: My get_items code. Here is important just one line with filter.</p> <pre><code>get_items('GET', []) -&gt; Items = boss_db:find(item, []), S = Req:query_param("start"), F = Req:query_param("finish"), Start = string_to_datetime(S), Finish = string_to_datetime(F), Fitems = filter(Items, Start, Finish, []), {json, [{items, Fitems}]}. </code></pre> <p>create_item code. My datetime using my own function.</p> <pre><code>create_item('POST', []) -&gt; Lastname = Req:post_param("lastname"), User = hd(boss_db:find(consumer, [{lastname, Lastname}])), DateTime = datetime_to_string(calendar:now_to_local_time(erlang:now())), Type = Req:post_param("type"), IdType = Req:post_param("idtype"), Item = item:new(id, User:id(), DateTime, Type, IdType), case Item:save() of {ok, SavedItem} -&gt; {json, [{status, "ok"}]}; {error, Reason} -&gt; {json, [{error, Reason}]} end. </code></pre> <p>My function to converting datetime to string.</p> <pre><code>datetime_to_string({{YY, MM, DD}, {Hour, Min, Sec}}) -&gt; io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", [YY, MM, DD, Hour, Min, Sec]). </code></pre> <p>My function to converting string to datetime.</p> <pre><code>string_to_datetime(S) -&gt; {YY, _} = string:to_integer(string:substr(S, 1, 4)), {MM, _} = string:to_integer(string:substr(S, 6, 2)), {DD, _} = string:to_integer(string:substr(S, 9, 2)), {Hour, _} = string:to_integer(string:substr(S, 12, 2)), {Min, _} = string:to_integer(string:substr(S, 15, 2)), {Sec, _} = string:to_integer(string:substr(S, 18, 2)), {{YY, MM, DD}, {Hour, Min, Sec}}. </code></pre> <p>My filter method.</p> <pre><code>filter([], Start, Finish, Acc) -&gt; Acc; filter([Model|Models], Start, Finish, Acc) -&gt; DateTime = string_to_datetime(Model:datetime()), {D1, _} = calendar:time_difference(Start, DateTime), {D2, _} = calendar:time_difference(DateTime, Finish), if D1 &gt;= 0, D2 &gt;= 0 -&gt; filter(Models, Start, Finish, [Model | Acc]); true -&gt; filter(Models, Start, Finish, Acc) end. </code></pre> <p>And I have the error:</p> <pre><code>{function_clause, [{string,substr2, [&lt;&lt;"2013-12-17 18:36:42"&gt;&gt;,1], [{file,"string.erl"},{line,213}]}, {string,substr,3,[{file,"string.erl"},{line,208}]}, {cb_tracker_main_controller,string_to_datetime,2, </code></pre> <p>Please, help me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload