Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:44:27+00:00 2026-05-24T15:44:27+00:00

I have a string that needs to be turned into a date attribute to

  • 0

I have a string that needs to be turned into a date attribute to be stored in a Ruby database.
There is a javascript function that collects the data and submits it to a ruby method which in turn submits to the database. However one of the fields is a “Date” field. Not a “DateTime” field so i cannot use the Date() function provied by js. The string i have is already in the format needed its simply getting the db to recognise this.

the html

<form action="/submiteffort" id="effort_form" method="post">
    <input type="hidden" id="week_commencing" name="week_commencing" value="x">
    <input type="hidden" id="task_id" name="task_id" value="x">
    <input type="hidden" id="effort_hours" name="hours" value="0">
</form>
<!-- Javascript code to submit the hidden form -->
<script>
function submiteffort( elem, name )
{
    var date = getdate();
    $("#week_commencing").val(date);
    $("#effort_hours").val( $( elem ).val() );
    $("#task_id").val( name );
    $("#effort_form").submit();
    return true; 
}

getDate() function

function getdate()
{
    var myspan = document.getElementById('startDate');
    var span_textnode = myspan.firstChild;
    var span_text = span_textnode.data;
    myDateParts = span_text.split("/");

    var d = myDateParts[0];
    var dd = days(d);

    var m = myDateParts[1];
    var subSection2 = m.substring(1,0);

    if (subSection2 == "0") {
            mm = m;
    }
    else {
        mm = "0" + myDateParts[1];
    }


    var yy = myDateParts[2];

    var actDate = yy + "-" + mm + "-" + dd;
    return actDate;
}

submit method in the controller

def submit

    effort = Effort.new
    effort.user_id = 10 #current_user.id
    effort.project_task_id = params[:task_id]
    effort.week_commencing = params[:wc]
    effort.hours = params[:hours]
    effort.save

    respond_to do |format|
      format.html
      format.js 
    end
  end

How do i get my database to recognise that the value i want needs to the a “DATE” and submit it to the database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:44:29+00:00Added an answer on May 24, 2026 at 3:44 pm

    If you’re submitting a date in a format that Date recognizes, the conversion should be done for you. This requires that week_commencing is declared as a :date type column.

    Have a look at your log/development.log to see what the params are set to for the request in question. Make sure that the generated date is coming through correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string value that needs to be converted into my user defined
I have a piece of C# code that needs to convert a string array
I have a arbitrarily large string of text from the user that needs to
Say i have a string that i need to evaluate in javascript such as
Overview: I have an array of 20 byte strings that needs to be stored
I have a string like this that I need to parse into a 2D
I have a String representation of a date that I need to create a
I have string like &amp;auml;s&amp;aring; that needs to be converted like äså so how
I have a string that is a valid date but it is a string
Say I have a list of 10,000 lines of string that needs to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.