I am trying to display the current date in the correct format, for example: 12/19/2016. I am currently using Date.now() but it is showing a garbage value. I only want to display the date without the time. I have also tried using pipes, but they are not binding correctly with the database. Now, I am using formcontrol to get the current date using Date.now() and later displaying this date in an HTML grid. This is my current code: Date.js file:
var mongoose = require('mongoose');
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
PurchaseOrderSchema = new Schema({
PurchaseOrderNo: {
type: Number,
required: true,
index: {
unique: true
}
},
Status:String,
OrderDate: {
type: Date,
"default": Date.now()
}
}
{ collection: 'PurchaseOrder' });
PurchaseOrderSchema.set('toObject', { getters: true });
PurchaseOrderSchema.set('toJSON', { getters: true });
PurchaseOrderSchema.virtual('locationname').get(function() {
return this.Locations[0].ParentId.LocationName;
});
PurchaseOrderSchema.virtual('Tempvendor').get(function() {
return this.Vendors[0].ParentId.VendorName;
});
PurchaseOrderSchema.statics.delete_by_name = function(name, cb_succ, cb_fail) {};
var PurchaseOrder = mongoose.model('PurchaseOrder', PurchaseOrderSchema);
module.exports = PurchaseOrder;
newpurchaseorder.ts file:
export class NewPurchaseOrderComponent implements OnInit {
private PurchaseOrderNo = new FormControl("", Validators.required);
private OrderDate = new FormControl("");
this.OrderDate=Date.now();
ngOnInit() {
this.addClassForm = this.formBuilder.group({
PurchaseOrderNo:this.PurchaseOrderNo,
OrderDate: this.OrderDate,
});
}
}
newpurchageorder.html file:
<section class="page-form-ele page">
<section class="panel panel-default">
<div class="panel-heading"><span class="glyphicon glyphicon-th"></span>Purchase Order</div>
<div class="panel-body" data-ng-controller="TabsDemoCtrl">
<div class="row">
<div class="col-sm-12">
<div class="heading-container">
<div class="row">
<div class="col-sm-6 margin-top-13">
<h3 class="h3-color">New Purchase Order</h3>
</div>
<div class="col-sm-6" align="right">
<form class="form-horizontal margin-bottom-0 margin-top-6" [formGroup]="addClassForm" (ngSubmit)="submitAdd()" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Date:</label>
<div class="col-sm-4">
<input type="number" class="form-control" [(ngModel)]="OrderDate" id="orderdate" placeholder="Order Date..." formControlName="OrderDate" required readonly="true" >
</div>
</div>
</div>
</div>
</form>
</section>