Well you can use StringFormat
for specific DatePicker
date format (check this example: Changing the string format of the WPF DatePicker)
Here is a simple example (make sure ViewModel is proper DataContext for you xaml file)
Main Window
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var vm = new ViewModel();
DataContext = vm;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var context = (ViewModel) DataContext;
var date = context.SelectedDate;
MessageBox.Show(string.Format("Selected Date is {0:MM/dd/yy H:mm:ss zzz}", date));
}
}
View Model
public class ViewModel
{
public DateTime SelectedDate { get; set; }
}
Xaml file
<DatePicker VerticalAlignment="Top"
SelectedDate="{Binding SelectedDate}" />
<Button Content="Button"
HorizontalAlignment="Left"
Margin="10,74,0,0"
VerticalAlignment="Top"
Width="75"
Click="Button_Click" />
You can change the format of DateTime
when you show the MessageBox (check this: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx)
UPDATE
For (yy-day Of Year), you can use:
MessageBox.Show(string.Format("Selected Date is {0:yy-}{1}", date, date.DayOfYear));