How to convert only date and month to string from CalendarDatePicker

Multi tool use
Multi tool use












0















I am writing a simple code in UWP where the user can select date from CalendarDatePicker and the app will show the selected date in a TextBlock and do some functionalities. How can I do that?



I have tried to do it with ToString() method. It shows full form of the date (ex: 1/1/2019 10:27 AM +06:00)



But I want to show the date and the month only.



Here is the code that I've written:



XAML



<CalendarDatePicker Name="calDatePicker"
DateChanged="calDatePicker_DateChanged"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5,0,0,1"/>
<TextBlock Name="dateText"
Style="{StaticResource sampleText}"
Text="Preferred Time"/>


C#:



private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
dateText.Text = calDatePicker.Date.ToString();
counter = true;
}
}









share|improve this question

























  • This is a little problematic functionality. You can use ToLongDateString() or ToShortDateString() to display only a full date. But when you want do display only year and month, you need to use your specific format in ToString function. But there is problem with international compatibility. There is no way to get format for month and day only writing from system or support classes. It can be MM/dd (e.g. USA), or dd. MM. (e.g. many European countries) or MM月dd日 (Japan, and perhaps China). And therefore you need to determine custom format, or remove year from country format.

    – Julo
    Jan 1 at 4:51













  • Possible duplicate of C# DateTime to "YYYYMMDDHHMMSS" format

    – Mohamad Armoon
    Jan 1 at 4:56
















0















I am writing a simple code in UWP where the user can select date from CalendarDatePicker and the app will show the selected date in a TextBlock and do some functionalities. How can I do that?



I have tried to do it with ToString() method. It shows full form of the date (ex: 1/1/2019 10:27 AM +06:00)



But I want to show the date and the month only.



Here is the code that I've written:



XAML



<CalendarDatePicker Name="calDatePicker"
DateChanged="calDatePicker_DateChanged"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5,0,0,1"/>
<TextBlock Name="dateText"
Style="{StaticResource sampleText}"
Text="Preferred Time"/>


C#:



private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
dateText.Text = calDatePicker.Date.ToString();
counter = true;
}
}









share|improve this question

























  • This is a little problematic functionality. You can use ToLongDateString() or ToShortDateString() to display only a full date. But when you want do display only year and month, you need to use your specific format in ToString function. But there is problem with international compatibility. There is no way to get format for month and day only writing from system or support classes. It can be MM/dd (e.g. USA), or dd. MM. (e.g. many European countries) or MM月dd日 (Japan, and perhaps China). And therefore you need to determine custom format, or remove year from country format.

    – Julo
    Jan 1 at 4:51













  • Possible duplicate of C# DateTime to "YYYYMMDDHHMMSS" format

    – Mohamad Armoon
    Jan 1 at 4:56














0












0








0


1






I am writing a simple code in UWP where the user can select date from CalendarDatePicker and the app will show the selected date in a TextBlock and do some functionalities. How can I do that?



I have tried to do it with ToString() method. It shows full form of the date (ex: 1/1/2019 10:27 AM +06:00)



But I want to show the date and the month only.



Here is the code that I've written:



XAML



<CalendarDatePicker Name="calDatePicker"
DateChanged="calDatePicker_DateChanged"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5,0,0,1"/>
<TextBlock Name="dateText"
Style="{StaticResource sampleText}"
Text="Preferred Time"/>


C#:



private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
dateText.Text = calDatePicker.Date.ToString();
counter = true;
}
}









share|improve this question
















I am writing a simple code in UWP where the user can select date from CalendarDatePicker and the app will show the selected date in a TextBlock and do some functionalities. How can I do that?



I have tried to do it with ToString() method. It shows full form of the date (ex: 1/1/2019 10:27 AM +06:00)



But I want to show the date and the month only.



Here is the code that I've written:



XAML



<CalendarDatePicker Name="calDatePicker"
DateChanged="calDatePicker_DateChanged"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5,0,0,1"/>
<TextBlock Name="dateText"
Style="{StaticResource sampleText}"
Text="Preferred Time"/>


C#:



private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
dateText.Text = calDatePicker.Date.ToString();
counter = true;
}
}






c# xaml datetime uwp uwp-xaml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 11:28









marc_s

577k12911141259




577k12911141259










asked Jan 1 at 4:37









Mahmudul HasanMahmudul Hasan

53




53













  • This is a little problematic functionality. You can use ToLongDateString() or ToShortDateString() to display only a full date. But when you want do display only year and month, you need to use your specific format in ToString function. But there is problem with international compatibility. There is no way to get format for month and day only writing from system or support classes. It can be MM/dd (e.g. USA), or dd. MM. (e.g. many European countries) or MM月dd日 (Japan, and perhaps China). And therefore you need to determine custom format, or remove year from country format.

    – Julo
    Jan 1 at 4:51













  • Possible duplicate of C# DateTime to "YYYYMMDDHHMMSS" format

    – Mohamad Armoon
    Jan 1 at 4:56



















  • This is a little problematic functionality. You can use ToLongDateString() or ToShortDateString() to display only a full date. But when you want do display only year and month, you need to use your specific format in ToString function. But there is problem with international compatibility. There is no way to get format for month and day only writing from system or support classes. It can be MM/dd (e.g. USA), or dd. MM. (e.g. many European countries) or MM月dd日 (Japan, and perhaps China). And therefore you need to determine custom format, or remove year from country format.

    – Julo
    Jan 1 at 4:51













  • Possible duplicate of C# DateTime to "YYYYMMDDHHMMSS" format

    – Mohamad Armoon
    Jan 1 at 4:56

















This is a little problematic functionality. You can use ToLongDateString() or ToShortDateString() to display only a full date. But when you want do display only year and month, you need to use your specific format in ToString function. But there is problem with international compatibility. There is no way to get format for month and day only writing from system or support classes. It can be MM/dd (e.g. USA), or dd. MM. (e.g. many European countries) or MM月dd日 (Japan, and perhaps China). And therefore you need to determine custom format, or remove year from country format.

– Julo
Jan 1 at 4:51







This is a little problematic functionality. You can use ToLongDateString() or ToShortDateString() to display only a full date. But when you want do display only year and month, you need to use your specific format in ToString function. But there is problem with international compatibility. There is no way to get format for month and day only writing from system or support classes. It can be MM/dd (e.g. USA), or dd. MM. (e.g. many European countries) or MM月dd日 (Japan, and perhaps China). And therefore you need to determine custom format, or remove year from country format.

– Julo
Jan 1 at 4:51















Possible duplicate of C# DateTime to "YYYYMMDDHHMMSS" format

– Mohamad Armoon
Jan 1 at 4:56





Possible duplicate of C# DateTime to "YYYYMMDDHHMMSS" format

– Mohamad Armoon
Jan 1 at 4:56












1 Answer
1






active

oldest

votes


















1














private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
var dt = calDatePicker.Date;
dateText.Text = dt.Value.Year.ToString() + " " + dt.Value.Month.ToString();
counter = true;
}
}





share|improve this answer


























  • I used year and month for example, you can use everything you need.

    – CodeMan
    Jan 1 at 4:47











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993038%2fhow-to-convert-only-date-and-month-to-string-from-calendardatepicker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
var dt = calDatePicker.Date;
dateText.Text = dt.Value.Year.ToString() + " " + dt.Value.Month.ToString();
counter = true;
}
}





share|improve this answer


























  • I used year and month for example, you can use everything you need.

    – CodeMan
    Jan 1 at 4:47
















1














private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
var dt = calDatePicker.Date;
dateText.Text = dt.Value.Year.ToString() + " " + dt.Value.Month.ToString();
counter = true;
}
}





share|improve this answer


























  • I used year and month for example, you can use everything you need.

    – CodeMan
    Jan 1 at 4:47














1












1








1







private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
var dt = calDatePicker.Date;
dateText.Text = dt.Value.Year.ToString() + " " + dt.Value.Month.ToString();
counter = true;
}
}





share|improve this answer















private void calDatePicker_DateChanged(CalendarDatePicker sender, CalendarDatePickerDateChangedEventArgs args)
{
if (calDatePicker.Date < DateTime.Now)
{
dateText.Text = "Order must be placed between this day and next 5 days.";
}
else
{
var dt = calDatePicker.Date;
dateText.Text = dt.Value.Year.ToString() + " " + dt.Value.Month.ToString();
counter = true;
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 5:12

























answered Jan 1 at 4:46









CodeManCodeMan

557311




557311













  • I used year and month for example, you can use everything you need.

    – CodeMan
    Jan 1 at 4:47



















  • I used year and month for example, you can use everything you need.

    – CodeMan
    Jan 1 at 4:47

















I used year and month for example, you can use everything you need.

– CodeMan
Jan 1 at 4:47





I used year and month for example, you can use everything you need.

– CodeMan
Jan 1 at 4:47




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993038%2fhow-to-convert-only-date-and-month-to-string-from-calendardatepicker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







v4zFmc x 4dK,rFyWm,8aujPc,WFe1Q4O8,aA,52JyZN,2VxF Lrl,Cx2 i4
ocI8r0RAED,q6 IXl4A1,nV4IIp7r,124ZxYWujj0slysfOb6rC5i,RcWULdrMItmOUgyD,ITI2y54aCA 6I0,1AFg69QVah 9A

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas