我正在尝试创建一个宏,将用户输入的截止日期带入单元格var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
const Event = require('../../model/event.model');
const multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads/');
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
});
var upload = multer({ storage: storage }).single('eventimage');
/* SAVE EVENT */
//app.post('/api/image', upload.array('image', 5), (req, res, next) => {
router.post('/', function(req, res, next) {
upload(req, res, function(err) {
console.log(req.file); //showing undefined
console.log(req.files); //showing undefined
if (err) {
// An error occurred when uploading
throw err;
}
res.json({
sucess: true,
message: 'Image was uploaded successfully'
});
// Everything went fine
});
});
,然后检查是否与截止日期已过的今天的日期相比较。此外,我正在尝试在单元格E2
中显示一个计数,显示截止日期前剩余的天数,或截止日期之前的天数。我有以下代码,但它没有正确计算日期,我不确定截止日期检查是否正常运行:
F2
答案 0 :(得分:2)
我认为你不需要VBA。请记住,Excel将日期存储为自00/01/1900以来过期的天数。
因此,如果您想知道E2
中的日期是否在A1
的截止日期之前或之后,您可以直接进行比较=IF(E2<=A1,"Deadline not passed","Deadline passed")
。< / p>
截止日期之前或之后的天数只是差异:E2-A1
。
编辑:我只是注意到您想要与今天的日期进行比较。正如克里斯的评论所暗示的,你可以使用=TODAY()
来获得这个。
答案 1 :(得分:0)
如果你想沿着VBA路线前进,我修改了代码:
Sub Test()
Dim DDate As Date
' Change the date value 20180101 entered in to excel date format, as yyyy/mm/dd
Range("E2").TextToColumns Destination:=Range("E2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 5), TrailingMinusNumbers:=True
DDate = Range("E2").Value
If DDate < Date Then 'calculate whether the due date (DDate) has passed, and do something if yes)
Range("G1") = "ERROR"
Else
Range("F2").Value = DDate - Date
End If
End Sub