Format date to or from Firebase database

I am storing some data in a Firebase database , that is no problem

Now want to store a date and now the is a issue

In a Datepicker there is the date to day.

When i store the date there is also the time after the date .

What do i change to store it or show it without the time

Maybe change Wanneer.Date ( this is the Datepicker)?????/


Code to save

` private async void BtnAdd_Clicked(object sender, EventArgs e)
{

       txtWie.Text = txtWie.Text + "  -  " + Wanneer.Date;

            await firebaseHelper.AddPerson(Convert.ToInt32(txtId.Text), txtName.Text, txtWie.Text, Wanneer.Date);
            txtId.Text = string.Empty;
            txtName.Text = string.Empty;
            txtWie.Text = string.Empty;
            await DisplayAlert("Bericht toegevoegd.", "", "OK");
            var allPersons = await firebaseHelper.GetAllPersons();
            lstPersons.ItemsSource = allPersons;
            await Navigation.PushAsync(new MainPage());

        }

    }`

And how to show the data

` protected async override void OnAppearing()
{

        base.OnAppearing();
        var allPersons = await firebaseHelper.GetAllPersons();
        lstPersons.ItemsSource = allPersons;
    }`

Answers

  • BorisopritBorisoprit Member ✭✭

    Maybe i am looking at it wrong

    I think something has to change here in the Datepicker ?

    <DatePicker x:Name="Wanneer" Format="dd-MM-yyyy" />

    I like to have the outcome in the database 22-09-2019
    And not 22-09-2019 00:00:00

    But what format to use

  • DirkWilhelmDirkWilhelm USMember ✭✭✭✭

    The date will always have a time component in your database. The only way to save it without the time is to change the type of your date column in your database to string, convert your datetime to a string and then save that. But thats a bit clumsy. You will always have to convert it to and from that string if you want to use or change it.

    I think the better way is just to format the output in your app:

    txtWie.Text = txtWie.Text + " - " + Wanneer.Date.ToString("dd-MM-yyyy");

  • BorisopritBorisoprit Member ✭✭

    DirkWilhem ,

    Thanks for the explanation .

    Well i found another workaround , in a label i put the date en save that as a string. Works but not what i was planning.

    <Label x:Name="Dag" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{0:dd-MM-yyyy }'}/>

    But maybe i use the time also , don't know . What looks best i think

    With the time of starting

    <Label x:Name="Dag" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{0:dd-MM-yyyy HH:mm}'}/>

Sign In or Register to comment.